我正在尝试使用Laravel 4.2 + OAuth2。我正在使用这个包:ardarek-oauth-4-laravel for Laravel。这是我的相关文件。
问题:无法检索Google通讯录列表。
// Config - app/config/packages/artdarek/oauth-4-laravel/config.php - 'consumers'
Google' => array(
'client_id' => '**********',
'client_secret' => '*******',
'scope' => array('https://www.googleapis.com/auth/tasks', 'https://www.google.com/m8/feeds/')
),
// Controller
public function importGoogleContacts() {
$code = Input::get('code'); // get data from input
$googleService = OAuth::consumer('Google'); // get google service
// if code is provided get user data and sign in
if (!empty($code)) {
Log::info('authorised');
// This was a callback request from google, get the token
$token = $googleService->requestAccessToken($code);
// Send a request with it
// $result = json_decode($googleService->request('https://www.googleapis.com/tasks/v1/lists/MDkyOTg5ODc5NDYw/tasks'), true);
$result = json_decode($googleService->request('https://www.google.com/m8/feeds/contacts/default/full'), true);
return Response::json($result);
}
// if not ask for permission first
else {
Log::info('not authorised');
$url = $googleService->getAuthorizationUri(); // get googleService authorization
Log::info('URL: ' . $url);
return Redirect::to((string)$url); // return to google login url
}
}
我尝试了userprofile
和tasks
API。两者都运行良好 - 我能够检索userProfile
信息和Tasks List
。但是,当我尝试联系时,它会回显一个空洞的结果。知道如何解决这个问题吗? Laravel还有其他套餐吗?
提前致谢 - 安吉
答案 0 :(得分:1)
Google Contacts API默认返回XML,而非许多其他Google API的JSON。要让它返回JSON,请将?alt=json
附加到网址。