问题
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.
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
}
}
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?
Thanks in advance - Anji
回答1:
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.
来源:https://stackoverflow.com/questions/26471562/laravel-google-contacts-api-gives-empty-results