2014-10-20 27 views
0

我试图使用Laravel 4.2 + OAuth2。我正在使用这个包:Laravel的ardarek-oauth-4-laravel。这是我的相关文件。Laravel:Google联系人API给出了空的结果

问题:无法检索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 
    } 
} 

我试图userprofiletasks的API。两者都正常工作 - 我能够检索userProfile信息和Tasks List。但是,当我尝试联系时,它会回应一个空洞的结果。任何想法如何解决这个问题? Laravel还有其他套餐吗?

在此先感谢 - 安吉

回答

1

的谷歌联系人API返回的XML默认情况下,不JSON像许多其他谷歌的API。要让它返回JSON,请将URL追加?alt=json

+0

谢谢了。经过测试,它的功能就像一个魅力。我实际上开始使用Google API PHP客户端而不是此包。 – Anji 2014-10-21 15:23:22