fc2ブログ

記事一覧

Googleカレンダーに接続できない場合の確認方法 | Xamarin.Forms


前回、XamarinでGoogleカレンダーに接続する方法をご紹介いたしましたが、接続する際に様々なリターンコードが出力され、正しく接続することに手間取りましたので、ここにトラブルシューティング方法を記載いたします。誰かの助けとなれば幸いです。


xamarin_rest_03.png



前提条件
・Windows10 Pro 64Bit
・Visual Studio 2015 Community Update3
・Xamarin 4.4.0.34 (NuGet Xamarin.Forms 2.3.4.247)
・macOS Sierra 10.12.4 / Xcode8.3.1 / Xamarin.iOS 10.8.0.1



1.Code 401 Login Required

リターンコード401の場合は、正しくログイン認証ができておりません。Google SignInで認証の上、アクセストークンをHttpヘッダーに付け加えてGoogleカレンダーのURLにアクセスしましょう。(※前回の記事をご確認ください)

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}



2.Code 401 Invalid Credentials

Androidで発生し得ます。
アクセストークンの取得方法が間違っていませんか?
誤)googleSignInResult.SignInAccount.IdToken
正)Android.Gms.Auth.GoogleAuthUtil.GetToken(context, account, scope)
(※GoogleAuthUtil.GetTokenは非同期処理にしてください。詳しくは次の記事にて)

{
 'error': {
  'errors': [
   {
    'domain': 'global',
    'reason': 'authError',
    'message': 'Invalid Credentials',
    'locationType': 'header',
    'location': 'Authorization'
   }
  ],
  'code': 401,
  'message': 'Invalid Credentials'
 }
}



3.取得したトークンが有効かどうか確認する

以下のURLのように取得したトークンをつけてブラウザでアクセスします。
https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

※URLパラメータの注意
Androidの場合は access_token=xxxxxxxxxxxxxxxxxxxxxxx
iOSの場合は id_token=xxxxxxxxxxxxxxxxxxxxxxx
置き換えてください。

正しく認証されている場合、以下のように表示されます。

{
 "azp": "999999999999-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com",
 "aud": "999999999999-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com",
 "sub": "999999999999999999999",
 "scope": "https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile",
 "exp": "9999999999",
 "expires_in": "3374",
 "email": "xxxxxxxx@gmail.com",
 "email_verified": "true",
 "access_type": "offline"
}



4.Code 403 Forbidden

403 Forbiddenが返される場合、Google API Consoleでカレンダーへのアクセスが無効に設定されている可能性があります。

カレンダーにアクセスできるかどうか確認するにはまず、以下のURLのようにトークンを付けてブラウザでアクセスしてください。
https://www.googleapis.com/calendar/v3/users/me/calendarList?access_token=xxxxxxxxxxxxxxxxxxxxxx

以下のようにCode:403が返される場合、Google API Console で有効にします。

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "accessNotConfigured",
    "message": "Access Not Configured. Calendar API has not been used in project 999999999999 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/calendar.googleapis.com/overview?project=999999999999 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
    "extendedHelp": "https://console.developers.google.com/apis/api/calendar.googleapis.com/overview?project=999999999999"
   }
  ],
  "code": 403,
  "message": "Access Not Configured. Calendar API has not been used in project 999999999999 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/calendar.googleapis.com/overview?project=999999999999 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry."
 }
}


ダッシュボードからカレンダーAPIを選択し、有効にするリンクをクリックします。

xamarin_rest_04.png



5.Code 400 Bad Request

接続後の更新時などに出力されるエラーです。次回の記事にてご紹介しております。



6.その他のエラーについて

以下のサイトで確認ができます。
https://developers.google.com/drive/v3/web/handle-errors




当ブログの内容をまとめた Xamarin逆引きメニュー は以下のURLからご覧になれます。
https://itblog.dynaspo.com/blog-entry-81.html


関連記事

コメント

コメントの投稿

※名前とタイトルが入力されていないコメントでは他のコメントとの区別ができません。

 入力されていないコメントには返信しませんのであらかじめご了承くださいませ。

※ニックネームでも良いので必ずご入力ください。

    

※必ずご入力ください。

    
    

※必ずご入力ください。

※技術的な質問には環境やエラーについて正確かつ詳細にお教えください。

・正確なエラーの内容

・Windowsのバージョン番号

・Visual Studioのバージョン

・機器の型番

・アプリやソフトのバージョン

    

カテゴリ別記事一覧

広告

プロフィール

石河 純


著者名 :石河 純
自己紹介:素人上がりのIT技術者。趣味は卓球・車・ボウリング

IT関連の知識はざっくりとこんな感じです。
【OS関連】
WindowsServer: 2012/2008R2/2003/2000/NT4
Windows: 10/8/7/XP/2000/me/NT4/98
Linux: CentOS RedHatLinux9
Mac: macOS Catalina 10.15 / Mojave 10.14 / High Sierra 10.13 / Sierra 10.12 / OSX Lion 10.7.5 / OSX Snow Leopard 10.6.8
【言語】
VB.net ASP.NET C#.net Java VBA
Xamarin.Forms
【データベース】
Oracle 10g/9i
SQLServer 2016/2008R2/2005/2000
SQLAnywhere 16/11/8
【BI/レポートツール】
Cognos ReportNet (IBM)
Microsoft PowerBI
ActiveReport (GrapeCity)
CrystalReport
【OCX関連】
GrapeCity InputMan SPREAD MultiRow GridView
【ネットワーク関連】
CCNP シスコ技術者認定
Cisco Catalyst シリーズ
Yamaha RTXシリーズ
FireWall関連
【WEB関連】
SEO SEM CSS jQuery IIS6/7 apache2

休みの日は卓球をやっています。
現在、卓球用品通販ショップは休業中です。