Laravel 5.0 Communicating with Wunderlist
I have created a custom provider for Laravel Socialite. The authentication part is going well until I try to call a user method.
Not sure what will go wrong. The wunderlist method documentation
My code:
/**
* {@inheritdoc}
*/
protected function getUserByToken($token)
{
$response = $this->getHttpClient()->get('https://a.wunderlist.com/api/v1/users', [
'X-Access-Token: ' . $token . ' X-Client-ID: ' . $this->clientId
]);
return json_decode($response->getBody(), true);
}
I am getting the following error:
InvalidArgumentException in MessageFactory.php line 202:
allow_redirects must be true, false, or array
Am I missing things in the parameter array?
Yos
source to share
In fact, the public shouldn't be doing something like that. But you can use Guzzle instead. There is a good video in the larakasts. Just find it Easy HTTP Requests
. And here's the code you can use to hum:
$client = new \Guzzle\Service\Client('a.wunderlist.com/api/v1/');
$response = $client->get('user')->send();
// If you want this response in array:
$user = $response->json();
Just read the docs here.
source to share
There is no problem when using this with straight twist. As far as I can see, the problem is with the headers that I will be analyzing.
The next solution is something I can live with, although it's not perfect.
$headers = array();
$headers[] = 'X-Access-Token: ' . $token;
$headers[] = 'X-Client-ID: ' . $this->clientId;
$response = $this->getHttpClient()->get('a.wunderlist.com/api/v1/user', [
'config' => [
'curl' => [
CURLOPT_POST => 0,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYPEER => false
]
]
]);
return json_decode($response->getBody(), true);
source to share