我一直在嘗試使用Google Mirror API來爲Google Glass編寫示例應用程序。我下載了Google Mirror API的PHP快速入門,並將其部署到由cPanel管理的Apache網絡服務器。我根據Glass Developers網站上發佈的指南配置了API密鑰等。當我轉到我的計算機上的URL以驗證應用程序時,我已成功重定向到Google的Oauth2服務,以授權我的Google帳戶。然而,當我回到網站繼續下去,我得到這個錯誤:未捕獲的異常'Google_AuthException'帶有消息'Could not json decode the token'
Fatal error: Uncaught exception 'Google_AuthException' with message 'Could not json decode the token' in /home/fluffy/public_html/glass/google-api-php-client/src/auth/Google_OAuth2.php:162 Stack trace: #0 /home/fluffy/public_html/glass/google-api-php-client/src/Google_Client.php(170): Google_OAuth2->setAccessToken(NULL) #1 /home/fluffy/public_html/glass/util.php(77): Google_Client->setAccessToken(NULL) #2 /home/fluffy/public_html/glass/oauth2callback.php(45): bootstrap_new_user() #3 {main} thrown in /home/fluffy/public_html/glass/google-api-php-client/src/auth/Google_OAuth2.php on line 162
於是我走進了劇本,把它試圖解析呼應出到頁面的JSON。 JSON數組其輸出是:
{ "access_token" : "ya29.1.AADtN_VWpFG9CblS1rWSrxcj1a1arQlIv4Iuu7mQ6UWMp9kRRLpr3tsuxRIDePA3ufvi-Q", "token_type" : "Bearer", "expires_in" : 3600, "id_token" : "eyJhbGciOiJSUzI1NiIsImtpZCI6IjQ3NzZmZWE1ZWRkMzU0OTJlYmNiYWY0N2QzZTQwNWQ5NTEwYzBmYmUifQ.eyJpc3MiOiJhY2NvdW50cy5nb29nbGUuY29tIiwidG9rZW5faGFzaCI6IjRCczhpSGNiSk5qUHlYYm41SndSVFEiLCJhdF9oYXNoIjoiNEJzOGlIY2JKTmpQeVhibjVKd1JUUSIsImNpZCI6IjU1OTc1MjgyNjgzOC5hcHBzLmdvb2dsZXVzZXJjb250ZW50LmNvbSIsImF6cCI6IjU1OTc1MjgyNjgzOC5hcHBzLmdvb2dsZXVzZXJjb250ZW50LmNvbSIsImF1ZCI6IjU1OTc1MjgyNjgzOC5hcHBzLmdvb2dsZXVzZXJjb250ZW50LmNvbSIsImlkIjoiMTAyMjUxNzA3OTUyNTQ3MjY3NjEwIiwic3ViIjoiMTAyMjUxNzA3OTUyNTQ3MjY3NjEwIiwiaWF0IjoxMzg3MTYxODk5LCJleHAiOjEzODcxNjU3OTl9.AXsIeC3f0e66ko5o2hxUXrE6LxYnSDXp0CwaSHBQKsd2M4d3g6A-JWeNIVYRTeoXucaFvDlr_XpLEtWeELZ1M8ExI85aWMwI6_xI969te4xX6pLtym2e84PzZGYwMZVmX_imAl4CFB9l5nYrZO7vSelGeXsON474QUvkTbMLTEM", "refresh_token" : "REDACTED" }
所以,我真的不明白這一點。爲什麼JSON會進入正常狀態,但腳本無法解析它?我已經在其他網站上發佈了其他Google地圖,但沒有明確的答案。
您的原始問題包含刷新令牌的值。保持這個令牌不公開。由於它已被共享,因此您可能需要訪問accounts.google.com並撤消授權以禁用令牌。 – mimming