dongli8979 2012-10-20 13:32
浏览 38

谷歌+ API无法正常工作

My google+ api code was working. Suddenly I get an error on the following line. Any help is appreciated.

if (isset($_SESSION['access_token'])) {
$client->setAccessToken($_SESSION['access_token']);
}

The error message is as follows

 Warning: json_decode() expects parameter 1 to be string, array given in /opt/bitnami/apache2/htdocs/goo/src/auth/apiOAuth2.php on line 142 Fatal error: Uncaught exception 'apiAuthException' with message 'Could not json decode the access token' in /opt/bitnami/apache2/htdocs/goo/src/auth/apiOAuth2.php:144 Stack trace: #0 /opt/bitnami/apache2/htdocs/goo/src/apiClient.php(186): apiOAuth2->setAccessToken(Array) #1 /opt/bitnami/apache2/htdocs/goo/googlep.php(1196): apiClient->setAccessToken(Array) #2 {main} thrown in /opt/bitnami/apache2/htdocs/goor/src/auth/apiOAuth2.php on line 144
  • 写回答

2条回答 默认 最新

  • douqiangchuai7674 2013-04-22 13:34
    关注

    I had the same error too a while ago. Actually this function setAccessToken only accepts json_encoded string ( simply saying the json encoded string that you get when user authenticates which has access token, refresh token, bearer etc etc). You have to pass that json encoded string to this function to set the access token . $client = new Google_Client();

    $token = $client->getAccessToken(); // get the token when google redirects the user after authentication to your redirect uri with the code. // $token will have json encoded string.

    $client->setAccessToken($token); // now set the access token here with that $token

    if you pass an array or anything else json encoded string to setAccessToken you will get this error.

    评论

报告相同问题?