Chrome 拡張機能を構築し、users.labels:createメソッドを使用して新しいラベルを作成しようとしています。アクセス トークンの取得に成功しました。アクセス許可は適切に設定されていると思いますが、まだ 400 を取得しています。
(私のコードがそれを与えない場合、これは私の最初の Web プロジェクトです。そのため、どんな助けも心から感謝しており、あなたの時間を感謝しています。)
background.js
var postRequestUrl = "https://www.googleapis.com/gmail/v1/users/me/labels?access_token=" + accessToken;
$.ajax({
url: postRequestUrl,
method: "POST",
contentType: "application/json",
data: {
name: "posting test label",
labelListVisibility: "labelShow",
messageListVisibility: "show"
}
}).done(function(msg){
alert("Success?")
})
マニフェスト.json
{
"manifest_version": 2,
"key": "redacted>",
"name": "<redacted>",
"description": "Description",
"version": "0.0.2.0",
"default locale": "en",
"icons": { "128": "imgs/pledge_pin.png"},
"content_scripts" : [
{
"matches": ["*://mail.google.com/mail/*"],
"js": ["js/jquery.js", "js/compose.js", "bower_components/jqnotifybar/jquery.notifyBar.js"],
"css": ["css/stylesheet.css", "bower_components/jqnotifybar/css/jquery.notifyBar.css"]
}
],
"background": {
"scripts": ["scripts/background.js", "js/jquery.js"]
},
"permissions": [
"identity",
"https://www.googleapis.com/*"
],
"oauth2": {
"client_id": "<redacted>",
"scopes": ["https://www.googleapis.com/auth/gmail.modify", "https://www.googleapis.com/auth/gmail.labels"]
}
}
完全なエラー メッセージ
POST https://www.googleapis.com/gmail/v1/users/me/labels?access_token=<token redacted> 400 (Bad Request)
n.ajaxTransport.k.cors.a.crossDomain.send @ jquery.js:4
n.extend.ajax @ jquery.js:4
(anonymous function) @ background.js:106
propertyNames.forEach.target.(anonymous function) @ extensions::SafeBuiltins:19
EventImpl.dispatchToListener @ extensions::event_bindings:395
propertyNames.forEach.target.(anonymous function) @ extensions::SafeBuiltins:19
$Array.forEach.publicClass.(anonymous function) @ extensions::utils:94
EventImpl.dispatch_ @ extensions::event_bindings:379
EventImpl.dispatch @ extensions::event_bindings:401
propertyNames.forEach.target.(anonymous function) @ extensions::SafeBuiltins:19
$Array.forEach.publicClass.(anonymous function) @ extensions::utils:94
messageListener @ extensions::messaging:188
propertyNames.forEach.target.(anonymous function) @ extensions::SafeBuiltins:19
EventImpl.dispatchToListener @ extensions::event_bindings:395
propertyNames.forEach.target.(anonymous function) @ extensions::SafeBuiltins:19
$Array.forEach.publicClass.(anonymous function) @ extensions::utils:94
EventImpl.dispatch_ @ extensions::event_bindings:379
EventImpl.dispatch @ extensions::event_bindings:401
propertyNames.forEach.target.(anonymous function) @ extensions::SafeBuiltins:19
$Array.forEach.publicClass.(anonymous function) @ extensions::utils:94
dispatchOnMessage @ extensions::messaging:316