Laravel:谷歌联系人API提供了空的结果 [英] Laravel: Google contacts API gives empty results
问题描述
我正在尝试使用Laravel 4.2 + OAuth2。我正在使用这个包:Laravel的ardarek-oauth-4-laravel。以下是我的相关文件。
I am trying to use Laravel 4.2 + OAuth2. I am using this package: ardarek-oauth-4-laravel for Laravel. Here are my related files.
问题:无法检索Google通讯录。
Problem: Unable to retrieve Google contacts lists.
// 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
和任务
API。这两个工作正常 - 我能够检索 userProfile
信息和任务列表
。但是,当我尝试联系时,它会回应一个空洞的结果。任何想法如何解决这个问题?有没有其他的软件包可用于Laravel?
I tried userprofile
and tasks
APIs. Both are working fine - I am able to retrieve userProfile
information and Tasks List
. But, when I try for contacts, it echos an empty result. Any idea how to solve this problem? Is there any other package available for Laravel?
在此先感谢 - Anji
Thanks in advance - Anji
推荐答案
默认情况下,Google Contacts API会返回XML,而不是像许多其他Google API一样返回JSON。要让它返回JSON,请在URL中追加?alt = json
。
The Google Contacts API returns XML by default, not JSON like many other Google APIs. To have it return JSON, append ?alt=json
to the URL.
这篇关于Laravel:谷歌联系人API提供了空的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!