尝试将 Classic ASP 与 Tumblr API 集成。我想自动化 The Tumblr 编写 API 以及来自 Classic ASP 网站的帖子。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。我需要知道如何从页面获取状态。即使是开始的提示也会很棒。一个解决方案,甚至更好。我已经使用 Classic 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
这是使用 Classic 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 帖子(照片、引用等)添加其他示例。