2017-01-03 31 views
1

私はこの文書を検索したり読んだりすることなくこの質問をしません。私はこれまで2日間過ごしました。私はsthがないと確信しています。 ドライブのスプレッドシートにgoogle認証を実装しようとしています。私はすべてを試みましたが、まだエラーメッセージ(redirect_uri_mismatch)を取得しています。基本的には、サイドパネルにログイン画面が必要です。ユーザーがボタンをクリックすると、auth magicが実行され、ユーザーがアクセスを許可すると別のhtmlに「成功」​​と表示されます。Googleスクリプトoauth2エラー:redirect_uri_mismatch

  1. 私はgoogle dev consoleでプロジェクトを作成しました。秘密
    131579675294-jc1c0ckuaa7n7ih7eevg19cisthgt00e.apps.googleusercontent.com

    2.2クライアント::XaebFsC18qfMmcZJKgokLEYo

  2. セットのコールバックURI:
    ます。https:// script.google資格情報
    2.1クライアントIDを作成

  3. .com/macros/d/MCgMJPIdD1bbeG1PsFaNug8uUifae5TWT/usercallback

  4. プロジェクトキー: MCgMJPIdD1bbeG1PsFaNug8uUifae5TWT

    スクリプトID: 1DYEShH45-AtikbEwfAG8w9P7Y39FHhCB-nGHWHOW4mUtq5DZLvubDxev

    おそらくprojectKey廃止されており、代わりにスクリプトIDはどちらも作品を使用する必要があります。私はのOAuth2使用

  5. ので、私はthe external libを追加しました:1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF

  6. 説明:私のGSファイルには、以下の次のコードを持っています。ボタンをクリックしたときにonSignIn()を呼び出すサイドバーがあります。私は認証でスプレッドシートにアクセスすることを期待しています。開始点として、私は認証ページを見たいと思っています。それを受け入れた後、私はcallback_uriであるページにリダイレクトして何かを簡単に表示したい。しかしそれは私にエラーを与えます。アイロニックステージは、作成したエンドポイントブラウザのリンクであり、正常にリダイレクトされました。

ENDPOINTブラウザLINK

https://accounts.google.com/o/oauth2/auth?redirect_uri=https%3A%2F%2Fscript.google.com%2Fmacros%2Fd%2FMCgMJPIdD1bbeG1PsFaNug8uUifae5TWT%2Fusercallback&response_type=code&client_id=131579675294-jc1c0ckuaa7n7ih7eevg19cisthgt00e.apps.googleusercontent.com&approval_prompt=force&scope=https%3A%2F%2Fdocs.google.com%2Ffeeds

私が間違って何をしているのですか?あなたの助けに感謝します。どうも。

var CLIENT_ID = '131579675294-jc1c0ckuaa7n7ih7eevg19cisthgt00e.apps.googleusercontent.com'; 

    var CLIENT_SECRET = 'XaebFsC18qfMmcZJKgokLEYo'; 

    function onSignIn() { 
     var service = getService(); 
     if (!service.hasAccess()) { 
      var authorizationUrl = service.getAuthorizationUrl(); 
      var template = HtmlService.createTemplate('<a href="<?= authorizationUrl ?>" target="_blank">Authorize</a>'); 
      template.authorizationUrl = authorizationUrl; 
      var page = template.evaluate(); 
      return HtmlService.createHtmlOutput(page); 
     } 
    } 


     function authCallback(request) { 
     var service = getService(); 
     var authorized = service.handleCallback(request); 
     if (authorized) { 
      return HtmlService.createHtmlOutput('Success!'); 
     } else { 
      return HtmlService.createHtmlOutput('Denied'); 
     } 
     } 



     function getService() { 
     return OAuth2.createService('spreadsheets_ozzy123') 

      .setAuthorizationBaseUrl('https://accounts.google.com/o/oauth2/auth') 

      .setTokenUrl('https://accounts.google.com/o/oauth2/token') 

      .setClientId(CLIENT_ID) 

      .setClientSecret(CLIENT_SECRET) 

      .setCallbackFunction('authCallback') 

      .setScope('https://docs.google.com/feeds') ; 
     } 




     function onOpen() { 
      SpreadsheetApp.getUi() // Or DocumentApp or FormApp. 
       .createMenu('Custom Menu') 
       .addItem('Show sidebar', 'showSidebar') 
       .addToUi(); 
     } 


     function showSidebar() { 
     var html = HtmlService.createTemplateFromFile('LoginSideMenu').evaluate(); 
      SpreadsheetApp.getUi().showSidebar(html); 
     } 


     function include(filename) { 
      return HtmlService.createHtmlOutputFromFile(filename).getContent(); 
     } 

FULL ERROR

400. That’s an error. 

Error: redirect_uri_mismatch 

The JavaScript origin in the request, https://n-g7vwwdjiqopmv3hpcys4noea4krn6nxax6uaoda-0lu-script.googleusercontent.com, does not match the ones authorized for the OAuth client. Visit https://console.developers.google.com/apis/credentials/oauthclient/131579675294-jc1c0ckuaa7n7ih7eevg19cisthgt00e.apps.googleusercontent.com?project=131579675294 to update the authorized JavaScript origins. 

Learn more 

Request Details 
redirect_uri=storagerelay://https/n-g7vwwdjiqopmv3hpcys4noea4krn6nxax6uaoda-0lu-script.googleusercontent.com?id=auth704130 
response_type=permission id_token 
scope=email profile openid 
openid.realm= 
client_id=131579675294-jc1c0ckuaa7n7ih7eevg19cisthgt00e.apps.googleusercontent.com 
ss_domain=https://n-g7vwwdjiqopmv3hpcys4noea4krn6nxax6uaoda-0lu-script.googleusercontent.com 
fetch_basic_profile=true 
gsiwebsdk=2 
That’s all we know. 
+0

@ShyamKansagraありがとうございました!私は、私が正しいクライアントIDを使用していたことをとても確信していました。リソース - >高度なサービスを通じてアクセスした後、私はそれが正しくないことを認識しました。正しいものに置き換えられましたが、まだ実行されませんでした。私は新しいシートを作り、すべてのコードを新しいシートに持って行きました。その後、それは働いた!私はあなたのコメントをどのように信用するかわかりません。お知らせ下さい。 – BinaryWo

+0

あなたは歓迎です:)私は答えとして同じコメントを追加しました。あなたはそれを受け入れることができます。 –

答えて

2
  1. ゴーリソースへ - >高度なサービスを提供しています。下部にあるGoogleデベロッパーコンソールをクリックします。

  2. あなたはAPIマネージャを開いていました。

  3. ここで、最も左側のパネルの資格情報に進みます。

  4. コードに表示されているのと同じクライアントIDを使用していることを確認してください。 また、2つのオプションがあります:認可されたjs起点と許可されたリダイレクトURL。
  5. URLのオプションでは、400エラーからの不一致のURLを貼り付けます。

保存してもう一度お試しください。

関連する問題