artdarek / oauth-4-laravel

OAuth Service Provider for Laravel 4
684 stars 216 forks source link

HTTP Code: HTTP/1.1 400 Bad Request #185

Open KamilCwiertnia opened 4 years ago

KamilCwiertnia commented 4 years ago

I have a problem

My code: ` public function importGmail() {

    $code = Request::get('code');
    $googleService = \OAuth::consumer('Google');
    if(!is_null($code)) {
        $token = $googleService->requestAccessToken($code);
        $result = json_decode($googleService->request('https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=400'), true);
        $emails = []; // initialize the new array
        foreach ($result['feed']['entry'] as $contact) {
            if (isset($contact['gd$email'])) { // Sometimes, a contact doesn't have email address
            $emails[] = $contact['gd$email'][0]['address'];
            }
        }   
        return $emails;
    }
    else {
        $url = $googleService->getAuthorizationUri();
        return redirect((string)$url);
    }
}`

Function return: HTTP Code: HTTP/1.1 400 Bad Request