Php Google联系人API:检索照片查询失败-联系人ID无效

Php Google联系人API:检索照片查询失败-联系人ID无效,php,google-contacts-api,google-client,Php,Google Contacts Api,Google Client,我试图检索照片的联系人使用谷歌联系人API根据。使用的PHP客户端库是。我成功获取代码和用户信息,但未能获取用户的照片数据 我得到的答复是: 照片查询失败-联系人ID无效 这是我用来获取用户照片数据的回调函数的PHP代码: $client = new Google_Client(); $client->setClientId(GOOGLE_APP_CLIENT_ID); $client->setClientSecret(GOOGLE_APP_CLIENT_SECRET); $cl

我试图检索照片的联系人使用谷歌联系人API根据。使用的PHP客户端库是。我成功获取代码和用户信息,但未能获取用户的照片数据

我得到的答复是:

照片查询失败-联系人ID无效

这是我用来获取用户照片数据的回调函数的PHP代码:

$client = new Google_Client();

$client->setClientId(GOOGLE_APP_CLIENT_ID);
$client->setClientSecret(GOOGLE_APP_CLIENT_SECRET);
$client->setRedirectUri(GOOGLE_APP_CLIENT_REDIRECT_URI);
$client->addScope("openid profile email https://www.google.com/m8/feeds");

// Create a OAuth 2 service instance
$oauth2 = new Google_Service_Oauth2($client);

// Get the access token using code.
if (isset($_GET['code'])) {
    // Authenticate the code
    $client->authenticate($_GET['code']);
    $_SESSION['access_code'] = $client->getAccessToken();
    
    // Set the access token
    $client->setAccessToken($_SESSION['access_token']);
    $temp_obj = $client->verifyIdToken();
    ....
    // Get the user's info
    $guser_info = $oauth2->userinfo->get();
    // Get the contact id
    $contact_id = $guser_info['id'];
    // Get the user email
    $user_email = $guser_info['email'];
    
    // Make an authenticated request to the photo
    $req = new Google_Http_Request("https://www.google.com/m8/feeds/photos/media/default/$contact_id");
    // For replacing above line with the following also got the same result.
    //$req = new Google_Http_Request("https://www.google.com/m8/feeds/photos/media/$user_email/$contact_id");
    
    // Make an authenticated request
    $val = $client->getAuth()->authenticatedRequest($req);
    
    print_r($val->getResponseBody());// Get "Photo query failed - invalid contact ID"
} ...
我已在console项目中启用了联系人API,并添加了范围
https://www.google.com/m8/feeds

检索到的id是否与用户的联系人id不同,或者是否有方法获取用户的联系人id,或者我的代码中有什么错误?
非常感谢您的帮助或意见。

我正在使用类似的代码获取用户配置文件图像(样式):


是。我可以从$user\u info获取照片URL。错误是由逻辑造成的。代码中的逻辑是错误的。它试图通过从当前用户的联系人列表中检索当前用户的详细信息来检索当前用户的照片。
<?php
//@see http://www.mrcasual.com/on/coding/laravel4-package-management-with-composer/
public function getSocial($action = '')
{
    // check URL segment
    if ($action == 'auth') {
        // process authentication
        try {
            Hybrid_Endpoint::process();
        }
        catch (Exception $e) {
            // redirect back to http://URL/social/
            return Redirect::to('login/social');
        }
        return;
    }
    try {
        // create a HybridAuth object
        $socialAuth = new Hybrid_Auth(app_path() . '/config/hybridauth.php');
        // authenticate with provider
        if($action != ''){
            if(in_array($action,array('google'))){
                $provider = $socialAuth->authenticate($action);
            }else{
                return Redirect::to('login');
            }
        }else{
            return Redirect::to('login');
        }
        // fetch user profile
        $userProfile = $provider->getUserProfile();
    }
    catch(Exception $e) {
        // exception codes can be found on HybBridAuth's web site
        return Redirect::to('login');
    }
    access user profile data
    echo "Connected with: <b>{$provider->id}</b><br />";
    echo "As: <b>{$userProfile->displayName}</b><br />";
    echo "<pre>" . print_r( $userProfile, true ) . "</pre><br />";
    echo "PhotoURL: {$userProfile->photoUrl}<br />";
    die();
}