EvaOAuth icon indicating copy to clipboard operation
EvaOAuth copied to clipboard

增加Laravel支持

Open AlloVince opened this issue 10 years ago • 3 comments

AlloVince avatar May 05 '15 06:05 AlloVince

image

laravel5 中

    public function __construct()
    {
        $this->service = new \Eva\EvaOAuth\Service('Weibo', [
            'key' => '*****',  //对应微博的API Key
            'secret' => '********', //对应微博的Secret
            'callback' => 'http://******/weibo-oauth' //回调地址
        ]);

    }

    public function index()
    {
        return view('welcome');
    }

    public function login()
    {
        $this->service->requestAuthorize();

    }

    public function weiboOauth()
    {
        $token = $this->service->getAccessToken();
        $httpClient = new \Eva\EvaOAuth\AuthorizedHttpClient($token);
        $response = $httpClient->get('https://api.weibo.com/2/statuses/public_timeline.json');

        return $response;
    }

nidesky avatar Jun 13 '15 09:06 nidesky

Hi 感谢反馈

看了一下,微博使用了一个自定义字符串OAuth2来标示Token,目前的处理方法是:

  1. 运行composer update升级EvaOAuth到1.0.2
  2. 在你的代码中添加一行:
    public function weiboOauth()
    {
        $token = $this->service->getAccessToken();
        $token->setTokenType('OAuth2');

        $httpClient = new \Eva\EvaOAuth\AuthorizedHttpClient($token);
        $response = $httpClient->get('https://api.weibo.com/2/statuses/public_timeline.json');

        return $response;
    }

AlloVince avatar Jun 13 '15 15:06 AlloVince

@AlloVince 好快的反馈速度,值得信赖。

nidesky avatar Jun 14 '15 02:06 nidesky