我正在尝试使用Google Apps脚本发布到tumblr。我了解到Tumblr使用OAuth V1。为了了解和测试API,我复制了GSuiteDevs Apps Script OAuth1 Twitter Sample code available at Github。
我在必要时进行了适当的修改。运行脚本后,出现错误400.8001
,根据Tumblr API Documentation,这是由于>
“当NPF JSON参数无效或格式错误时。”
下面提供了代码和错误:
var CONSUMER_KEY = 'XXXVQoZ0kLUYB7GDHzJZcXXXXXXXXXXXXXXXXXXXXXXXX'; var CONSUMER_SECRET = 'XXXXlLVQS2z3WpXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; /** * Authorizes and makes a request to the Tumblr API. */ function run() { var service = getService(); if (service.hasAccess()) { var url = 'https://api.tumblr.com/v2/blog/{MY BLOG IDENTIFIER COMES HERE}.tumblr.com/posts'; var payload = { "content": [ { "type": "text", "text": "Hello world!" } ] }; var response = service.fetch(url, { method: 'post', payload: payload }); var result = JSON.parse(response.getContentText()); Logger.log(JSON.stringify(result, null, 2)); } else { var authorizationUrl = service.authorize(); Logger.log('Open the following URL and re-run the script: %s', authorizationUrl); } } /** * Reset the authorization state, so that it can be re-tested. */ function reset() { var service = getService(); service.reset(); } /** * Configures the service. */ function getService() { return OAuth1.createService('Tumblr') // Set the endpoint URLs. .setAccessTokenUrl('https://www.tumblr.com/oauth/access_token') .setRequestTokenUrl('https://www.tumblr.com/oauth/request_token') .setAuthorizationUrl('https://www.tumblr.com/oauth/authorize') // Set the consumer key and secret. .setConsumerKey(CONSUMER_KEY) .setConsumerSecret(CONSUMER_SECRET) // Set the name of the callback function in the script referenced // above that should be invoked to complete the OAuth flow. .setCallbackFunction('authCallback') // Using a cache will reduce the need to read from // the property store and may increase performance. .setCache(CacheService.getUserCache()) // Set the property store where authorized tokens should be persisted. .setPropertyStore(PropertiesService.getUserProperties()); } /** * Handles the OAuth callback. */ function authCallback(request) { var service = getService(); var authorized = service.handleCallback(request); if (authorized) { return HtmlService.createHtmlOutput('Success!'); } else { return HtmlService.createHtmlOutput('Denied'); } }
错误如下所示:
异常:https://api.tumblr.com的请求失败,返回了代码400。服务器响应被截断:{“ meta”:{“ status”:400,“ msg”:“ Bad Request”},“ response”:[],“ errors” :[{“ title”:“ Bad Request”,“ code”:8001,“ detail”:“发布失败。请重试。”}]}(使用MutantHttpExceptions选项检查完整响应)(第457行,文件“ Service” “)
代码中的问题是什么?
我正在尝试使用Google Apps脚本发布到tumblr。我了解到Tumblr使用OAuth V1。为了了解想法并测试API,我复制了GSuiteDevs Apps脚本OAuth1 Twitter提供的示例代码...
[@ TheMaster的积分