this document에 따라 Google Contacts API를 사용하여 연락처의 사진을 가져 오려고합니다. 사용 된 PHP 클라이언트 라이브러리는 here입니다. 코드와 사용자 정보를 성공적으로 받았지만 사용자의 사진 데이터를 가져 오지 못했습니다.Google Contacts API : RetrivePhoto 검색어가 잘못되었습니다 - 유효하지 않은 연락처 ID
내가 가진 응답은 다음과 같습니다
합니다. 내가 콘솔 프로젝트사진 쿼리가 실패 - 유효하지 않은 접촉 ID
Contacts API
활성화 및 범위
https://www.google.com/m8/feeds
을 추가 한
$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"
} ...
:
이
내가 사용자의 사진 데이터를 얻기 위해 사용하고 콜백 함수의 PHP 코드입니다.가 연락 ID 사용자의 또는 얻을 수있는 방법이에서 다른 검색된 ID 사용자의 연락 ID 또는 내 코드에 뭔가 잘못?
도움이나 의견을 보내 주시면 감사하겠습니다.
<?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();
}
어쩌면 당신의 $guser_info
이미 사진에 대한 링크가 포함되어
코드의 논리가 잘못되었습니다. 현재 사용자의 연락처 목록에서 현재 사용자의 세부 정보를 검색하여 현재 사용자의 사진을 검색하려고합니다. –