【问题标题】:Laravel: Google contacts API gives empty resultsLaravel:谷歌联系人 API 给出空结果
【发布时间】:2014-10-20 17:35:12
【问题描述】:

我正在尝试使用 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 还有其他可用的包吗?

提前致谢 - 安吉

【问题讨论】:

    标签: php laravel laravel-4 google-api google-contacts-api


    【解决方案1】:

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

    【讨论】:

    • 非常感谢。刚刚经过测试,它就像一个魅力。我实际上开始使用 Google APIs PHP 客户端而不是这个包。
    猜你喜欢
    • 2017-05-11
    • 1970-01-01
    • 2016-10-08
    • 2020-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-09
    • 1970-01-01
    相关资源
    最近更新 更多