Laravel:谷歌联系API给出的结果是空的



我正在尝试使用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
    }
}

我尝试了userprofiletasks API。两者都运行良好——我能够检索userProfile信息和Tasks List。但是,当我尝试联系的时候,却得到了一个空洞的结果。知道如何解决这个问题吗?Laravel还有其他套餐吗?

提前感谢-安吉

Google联系人API默认返回XML,而不是像许多其他Google API那样返回JSON。要让它返回JSON,请将?alt=json附加到URL。

相关内容

  • 没有找到相关文章