我正在使用Tumblr API的Chrome扩展程序,将屏幕截图发布到我的特定Tumblr网站。我使用Oauth来执行此操作,但是从Tumblr获取访问令牌时遇到了一些问题。
授权过程的第一部分似乎有效,但之后失败了。我看过其他一些涉及相同内容的帖子,大多是this one,但我无法弄清楚我做错了什么。
manifest.json看起来像这样,
{
"manifest_version": 2,
"name": "Black Sand White Sand Grey Sand",
"description": "An extension for art",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_title": "Click on this I dare you!"
},
"background": {
"page": "background.html"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"css": ["blurry.css"],
"js": ["jquery-2.2.3.min.js", "script.js"]
}
],
"permissions": [
"alarms",
"activeTab",
"tabs",
"https://www.tumblr.com/oauth/request_token",
"https://www.tumblr.com/oauth/authorize",
"https://www.tumblr.com/oauth/access_token",
"http://black-sand-white-sand-grey-sand.tumblr.com/",
"<all_urls>"
],
"web_accessible_resources": [
"chrome_ex_oauth.html"
]
}
我下载了这个谷歌教程给我的4个文件,(https://developer.chrome.com/extensions/tut_oauth),我不确定我是否错误地实现了这些文件,或者我的背景页面是否有问题这搞砸了。
这是&#39; background.js&#39;,
var image;
var oauth = ChromeExOAuth.initBackgroundPage({
'request_url': 'https://www.tumblr.com/oauth/request_token',
'authorize_url': 'https://www.tumblr.com/oauth/authorize',
'access_url': 'https://www.tumblr.com/oauth/access_token',
'consumer_key': 'anonymous',
'consumer_secret': 'anonymous',
'scope': 'http://black-sand-white-sand-grey-sand.tumblr.com/',
'app_name': 'Black Sand White Sand Grey Sand'
});
function onAuthorized() {
var url = 'api.tumblr.com/v2/blog/black-sand-white-sand-grey-sand.tumblr.com/post';
var request = {
'method': 'POST',
'headers': {
'Content-Type': 'application/x-www-form-urlencoded'
},
'body': {
'type': 'photo',
'state': 'published',
'date': 'null',
'source': image,
'data': image,
'data64': image
}
}
oauth.sendSignedRequest(url, function(text, xhr) {
console.log(text);
});
}
function authorizeIt() {
oauth.authorize(onAuthorized);
}
function screenshot() {
chrome.tabs.captureVisibleTab(
null, {format: 'jpeg', quality: 100}, function(dataUrl) {
image = dataUrl;
authorizeIt();
});
}
初始授权有效,会显示一个要求访问的标签,但是当我点击“允许”时,它会卡在另一个重定向页面上,在控制台中它会给我这些错误,
GET https://www.tumblr.com/oauth/access_token?oauth_consumer_key=z0lAIsL6mGl4Ib…h_token=H3x59WDyfwf9xacNrHVk9mLhVncRD0gnmdiJcnjyZXhsxY1gal&oauth_verifier= 400 (Bad Request)
Uncaught Error: Fetching access token failed with status 400
我也认为这可能是&chrome;&lt; chrome_ex_oauth.html&#39;下面,但我不知道。我一直试图调整它,并在过去几天弄明白,但无法弄明白。任何帮助将不胜感激。
<!DOCTYPE html>
<!--
* Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
* source code is governed by a BSD-style license that can be found in the
* LICENSE file.
-->
<html>
<head>
<title>OAuth Redirect Page</title>
<style type="text/css">
body {
font: 16px Arial;
color: #333;
}
</style>
<script type="text/javascript" src="chrome_ex_oauthsimple.js"></script>
<script type="text/javascript" src="chrome_ex_oauth.js"></script>
<script type="text/javascript" src="onload.js"></script>
</head>
<body>
Redirecting...
</body>
</html>