嘗試將經典ASP與Tumblr API集成。我想自動化Tumblr編寫API以及經典ASP網站的帖子。 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和微軟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
下面是正確的代碼,經過反覆試驗,對於一個普通崗位的tumblr使用傳統的ASP。感謝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幾天其他例子。
內容類型,我應該用什麼呢?我想我越來越近,因爲我得到了「授權失敗」作爲文本響應。無論如何翻譯此頁面(http://zh.efreedom.com/Question/1-2326071/Sending-POST-Request-Cocoa-Tumblr)到上面的經典ASP示例。由於Tumblr API沒有提供實際的特定錯誤消息,因此這只是試驗和錯誤。 – Patriotec 2010-12-07 23:11:28