简体   繁体   English

Laravel 5.0社交名流与奇妙清单

[英]Laravel 5.0 Socialite with Wunderlist

I've created a custom Provider for Laravel Socialite. 我为Laravel Socialite创建了一个自定义Provider。 The authentication part is going well until i'll try to call the user method. 身份验证部分进展顺利,直到我尝试调用用户方法。

Not sure what's going wrong. 不确定出了什么问题。 Method documentation at wunderlist wunderlist上的方法文档

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 get the following error: 我收到以下错误:

InvalidArgumentException in MessageFactory.php line 202:
allow_redirects must be true, false, or array

Do i miss things in the options array? 我是否会错过选项数组中的内容?

Jos 乔斯

Actually socialite is not supposed to do something like this. 实际上,社交名流不应该做这样的事情。 But instead you may use Guzzle. 但相反,你可以使用Guzzle。 There is a good video at laracasts. 在laracasts有一个很好的视频。 Just search for Easy HTTP Requests . 只需搜索Easy HTTP Requests And here's the code that you may use for guzzle: 这是你可能用于guzzle的代码:

$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. 阅读这里的文档

When using this with straight forward curl there is no issue. 当使用直线卷曲时,没有问题。 As far as i can see the issue lies in the headers i'll parse. 据我所知,问题在于我将解析的标题。

The following 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM