Tumblr APIとの古典的なASP統合
-
09-10-2019 - |
質問
古典的なASPをTumblr APIと統合しようとしています。 Classic ASP Webサイトからの投稿とともにTumblr Write APIを自動化したいと思います。 Tumblr APIはここにあります: http://www.tumblr.com/docs/en/api.
これは、Tumblr APIの書き込みPHP例です。
// Authorization info
$tumblr_email = 'info@davidville.com';
$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 = "info@davidville.com"
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
Tumblrの投稿(写真、見積もりなど)の他の例を追加します http://www.genxts.com 数日で。
解決
古典的なASPを介してPOSTリクエストを実行するには、あなたがする必要があるのは、 MSXML2
ライブラリ(IE Ajaxで行うように):
getのパラメーターを作成するのと同じ方法で、URL文字列としてリクエストデータを作成します。それがurlencodedされていることを確認してください
dim request_data: request_data = "key1=value1&key2=value2"
リクエストオブジェクトを作成し、POST経由でURLに接続します。 3番目のパラメーターは、呼び出しが同期しているかどうかを決定します。おそらく、標準ではなく、オブジェクトのサーバーバージョンが必要です MSXML2.XMLHTTP
物体
dim http: set http = CreateObject("MSXML2.ServerXMLHTTP")
http.open "POST", "http://www.tumblr.com/api/write", false
必要なHTTPリクエストヘッダーを設定します
http.setRequestHeader "Content-type", "..."
リクエストデータをリクエストに追加します
http.send request_data
その後、応答にアクセスできます
dim text: text = http.responseText
また
dim xml: set xml = http.responseXML
返品しているデータの種類に応じて。これが便利なリンクです: http://msdn.microsoft.com/en-us/library/ms754586(v=vs.85).aspx
わかりました、私はこれを機能させることができました
dim http: set http = CreateObject("MSXML2.ServerXMLHTTP")
dim email: email = "email@example.com"
dim password: password = "*password"
dim content: content = content & "type=regular"
content = content & "&body=this is a test"
content = content & "&email=" & email
content = content & "&password=" & password
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 content
Response.Write http.responseText
URLエンコーディングが気に入らなかったようです。電子メールとパスワードではなかった他のコンテンツをエンコードしてみました
content = Server.URLEncode(content)
content = content & "&email=" & email
content = content & "&password=" & password
しかし、私は「投稿は空であってはならない」というメッセージを手に入れました