2016-10-25 10 views
0

Chromeの拡張機能を使用してGoogleシートからデータを読み取ろうとしていますが、アクセストークンを取得できません。これまでに行ったことです:Chrome拡張機能からChrome ID API経由でGoogleスプレッドシートにアクセス

  • Google APIコンソールでOAuth 2クライアントIDを作成しました。許可されたJavaScriptの起源に "http://localhost"と "https://localhost"を入力しました(私の拡張機能は現在localhostに入っているので)。
  • はChromeの拡張機能の manifest.jsonを含むように更新:
{ 
    "permissions": [ 
    "identity", 
    "https://docs.google.com/spreadsheets/" 
    ], 
    "oauth2": { 
    "client_id": "<enter-oauth2-client-id-here>", 
    "scopes": [ 
     "https://docs.google.com/spreadsheets" 
    ] 
    } 
} 
  • を追加しました。この時点で、バックグラウンドスクリプト
console.log("here"); // this point is hit 

var ci = chrome.identity; 
ci.getAuthToken({ interactive: true }, function(token) { 
    console.log("token: " + token); // none of this is hit 
    if (chrome.runtime.lastError) { 
     console.log(chrome.runtime.lastError); 
     return; 
    } 
    access_token = token; 
}); 

に次のコード、私は拡張子をリロードし、Chromeを私の資格情報を要求します(ci.getAuthToken({ interactive: true } ...)行が実行されます)。しかし、資格情報が正常に提供されると、他には何も起こりませんペン。私はトークンが決して検索されないと思うので、function(token){...}内のコードは実行されません。バックグラウンドコンソールには「ここ」のメッセージが表示されますが、その他のエラーは表示されません(何もエラーや警告などは表示されません)。

注:manifest.jsonoauth2:client_idの下に、私はGoogle APIコンソールで生成されたOAuth2クライアントIDを使用しています。

私には何が欠けていますか?

+0

"https://docs.google.com/spreadsheets" 

を変更_あまり意味がありません。あなたはどういう意味ですか? – Xan

+0

これはどの進歩ですか? –

答えて

0

あなたのscope for spreadsheetは間違っていると思います。 documentationに基づいてhttps://www.googleapis.com/auth/spreadsheetsである必要があります。

"私の拡張子は今にlocalhostであるため、" だから_

"https://www.googleapis.com/auth/spreadsheets" 
関連する問題