Classic ASPをTumblr APIと統合しようとしています。私はTumblr APIをClassic ASPのWebサイトからの投稿と一緒に自動化したいと思っています。 Tumblr APIは、http://www.tumblr.com/docs/en/apiにあります。Tumblr APIとの従来のASP統合
これはTumblr API用のPHPの書き込み例です。
// Authorization info
$tumblr_email = '[email protected]';
$tumblr_password = 'secret';
// Data for new record
$post_type = 'regular';
$post_title = 'The post title';
$post_body = 'This is the body of the post.';
// Prepare POST request
$request_data = http_build_query(
array(
'email' => $tumblr_email,
'password' => $tumblr_password,
'type' => $post_type,
'title' => $post_title,
'body' => $post_body,
'generator' => 'API example'
)
);
// Send the POST request (with cURL)
$c = curl_init('http://www.tumblr.com/api/write');
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $request_data);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($c);
$status = curl_getinfo($c, CURLINFO_HTTP_CODE);
curl_close($c);
// Check for success
if ($status == 201) {
echo "Success! The new post ID is $result.\n";
} else if ($status == 403) {
echo 'Bad email or password';
} else {
echo "Error: $result\n";
}
私はASPに変換しようとしています。私はページからステータスを戻す方法を知る必要があります。始めるヒントさえも素晴らしいだろう。解決策、さらに良い。私はこれまでのクラシックASPとMicrosoft XMLHttpObjectでこれを得ている:
' Authorization info
tumblr_email = "[email protected]"
tumblr_password = "secret"
' Data for new record
post_type = "regular"
post_title = "The post title"
post_body = "This is the body of the post."
' Prepare POST request
request_data = "email=" tumblr_email & "&" &
request_data = request_data & "password=" & tumblr_password & "&" &
request_data = request_data & "type=" & post_type & "&" &
request_data = request_data & "title=" & post_title & "&" &
request_data = request_data & "body=" & post_body & "&" &
request_data = request_data & "generator=Your Generator Name"
request_data = server.urlencode(request_data)
Dim objHttp, strQuery
strQuery = “http://www.tumblr.com/api/write”
set objHttp = Server.CreateObject(“Msxml2.ServerXMLHTTP”)
objHttp.open “GET”, strQuery, false
objHttp.send
Response.Write objHttp.ResponseText
Set objHttp = Nothing
はここでクラシックASPを使用してTumblrのに定期的にポストのため、試行錯誤の後、正しいコードです。ヘルプのために
https://stackoverflow.com/users/69820/oracle-certified-professionalに感謝します。
' Authorization info
tumblr_email = "your_registered_email"
tumblr_password = "your_tumblr_password"
' Data for new record
post_type = "regular"
post_title = "The post title"
post_body = "This is the body of the post."
' Prepare POST request
request_data = "email=" & tumblr_email & "&"
request_data = request_data & "password=" & tumblr_password & "&"
request_data = request_data & "type=" & post_type & "&"
request_data = request_data & "title=" & server.urlencode(post_title) & "&"
request_data = request_data & "body=" & server.urlencode(post_body)
set http = CreateObject("MSXML2.ServerXMLHTTP")
http.open "POST", "http://www.tumblr.com/api/write", false
http.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
http.setRequestHeader "Content-length", len(content)
http.setRequestHeader "Connection", "close"
http.send request_data
Response.Write http.responseText
私は数日中にhttp://www.genxts.comにTumblrの記事のための他の例(写真、引用符など)を追加することがあります。
URL文字列としてあなたと同じように、あなたの要求データを構築する:あなたがする必要があるすべては(あなたがIEのAjaxで行うように)MSXML2
ライブラリを使用している、従来のASPを経由してPOSTリクエストを実行するには
を得た他のコンテンツをエンコードしようとした?私は思いますよテキスト応答として「Authorization Failed」が表示されているため、近づいています。とにかくこのページ(http://efreedom.com/Question/1-2326071/Sending-POST-Request-Cocoa-Tumblr)を上記のClassic ASPの例に変換します。 Tumblr APIは実際の特定のエラーメッセージを出さないので、これは現時点で試行錯誤しただけです。 – Patriotec
あなたはほとんどそこにいました。私はAPIのドキュメントをチェックしなければならなかった。定期的な投稿にはタイトルと本文が必要です。また、電子メール、パスワード、タイプをserver.urlencodeしない場合は、それ以外のものはすべて動作します。良い助けを借りてくれてありがとう。 – Patriotec