2010-12-07 29 views
0

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リクエストを実行するには

答えて

0

GETのためのbuidパラメータそれはリクエストオブジェクトを作成し、ポストを経由してURLに接続

dim request_data: request_data = "key1=value1&key2=value2" 

をURLエンコードだことを確認してください。 3番目のパラメータは、コールが同期かどうかを決定します。おそらくあなたは

http.setRequestHeader "Content-type", "..." 

が要求

http.send request_data 
にリクエストデータを追加する必要がある任意のHTTPリクエストヘッダの代わりに標準 MSXML2.XMLHTTPオブジェクト

dim http: set http = CreateObject("MSXML2.ServerXMLHTTP") 
http.open "POST", "http://www.tumblr.com/api/write", false 

セットで、対象のサーバーのバージョンが必要です

あなたは

dim text: text = http.responseText 
0123経由で応答にアクセスできます

または

dim xml: set xml = http.responseXML 

あなたが戻っているデータの種類に応じました。ここでは便利なリンクです:http://msdn.microsoft.com/en-us/library/ms754586(v=VS.85).aspx


[OK]を、私は、これはURLエンコードを好きではなかったようだ

dim http: set http = CreateObject("MSXML2.ServerXMLHTTP") 

dim email: email = "[email protected]" 
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 

仕事を得ることができました。私はちょうど

content = Server.URLEncode(content) 
content = content & "&email=" & email 
content = content & "&password=" & password 

メール&パスワードではありませんでしたが、私は、私は何をコンテンツタイプを使用する必要があります「ポストは空にすることはできません」というメッセージ

+0

を得た他のコンテンツをエンコードしようとした?私は思いますよテキスト応答として「Authorization Failed」が表示されているため、近づいています。とにかくこのページ(http://efreedom.com/Question/1-2326071/Sending-POST-Request-Cocoa-Tumblr)を上記のClassic ASPの例に変換します。 Tumblr APIは実際の特定のエラーメッセージを出さないので、これは現時点で試行錯誤しただけです。 – Patriotec

+0

あなたはほとんどそこにいました。私はAPIのドキュメントをチェックしなければならなかった。定期的な投稿にはタイトルと本文が必要です。また、電子メール、パスワード、タイプをserver.urlencodeしない場合は、それ以外のものはすべて動作します。良い助けを借りてくれてありがとう。 – Patriotec

関連する問題