Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QQ关联登录之后,无法获取数据 #1

Open
forecho opened this issue Oct 13, 2013 · 9 comments
Open

QQ关联登录之后,无法获取数据 #1

forecho opened this issue Oct 13, 2013 · 9 comments

Comments

@forecho
Copy link

forecho commented Oct 13, 2013

QQ登录之后,没有获取到数据,页面显示为
array(4) { ["provider_uid"]=> string(0) "" ["access_token"]=> NULL ["refresh_token"]=> string(0) "" ["expires_in"]=> NULL }

@forecho forecho closed this as completed Oct 13, 2013
@forecho forecho reopened this Oct 13, 2013
@tlikai
Copy link
Owner

tlikai commented Oct 14, 2013

@forecho 我这边测试是没有问题的,你使用的是QQ互联的应用吗?

@forecho
Copy link
Author

forecho commented Oct 14, 2013

@tlikai 是的,应用处于未审核状态,不知道是否与这个有关系。还是返回上面的那个代码,没有值。

@tlikai
Copy link
Owner

tlikai commented Oct 14, 2013

@forecho 我这边也是未审核的应用,方便把你代码发上吗?

@forecho
Copy link
Author

forecho commented Oct 14, 2013

public function actionAuth($provider)
    {
        // 导入OAuth2China
        Yii::import('ext.OAuth2China.OAuth2China');
        // 配置给平台参数
      $providers = array(
        'weibo' => array(
            'id' => 'xxxx',
            'secret' => 'xxxxxxx',
        ),
        'qq' => array(
            'id' => 'xxxx',
            'secret' => 'xxxxxx',
        ),
        // 'douban' => array(
        //     'id' => 'API Key',
        //     'secret' => 'Secret',
        // ),
        // 'renren' => array(
        //     'id' => 'API key',
        //     'secret' => 'Secret key',
        // ),
    );

    $OAuth2China = new OAuth2China($providers);

    $provider = $OAuth2China->getProvider($provider);

    if(!isset($_GET['code']))
    {
        // 跳转到授权页面
        $provider->redirect('http://www.niyabizui.com');
    }
    else
    {
        $token = $provider->getAccessToken($_GET['code']);
        var_dump($token);
    }
}

代码就是这个
www.niyabizui.com/index.php?r=site/auth&provider=weibo
用微博登录的时候返回的数据是:

array(4) { ["provider_uid"]=> string(10) "1288042931"
["access_token"]=> string(32) "2.00znUK6BBEU_8Debcab03931Ze2BLE"
["refresh_token"]=> string(0) "" ["expires_in"]=> int(157679999) }

但是用QQ登录的时候,返回的还是那个代码:

array(4) { ["provider_uid"]=> string(0) "" ["access_token"]=> NULL
["refresh_token"]=> string(0) "" ["expires_in"]=> NULL }

2013/10/14 Kai Li [email protected]

@forecho https://github.com/forecho 我这边也是未审核的应用,方便把你代码发上吗?


Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-26237241
.

@tlikai
Copy link
Owner

tlikai commented Oct 14, 2013

@forecho 你在providers/OAuth2China_Provider_Qq.php文件下的resloveResponse方法中打印一下$response参数,看看输出结果是什么,应该就能找到问题在那了?

@forecho
Copy link
Author

forecho commented Oct 14, 2013

@tlikai 在esloveResponse方法的 if 外打印$response参数,报错为:
HTTP Status 400 - CGIError:400 bad request,not allow multipart!

@tlikai
Copy link
Owner

tlikai commented Oct 15, 2013

@forecho 好的,我今晚回去修复这个问题

@tlikai
Copy link
Owner

tlikai commented Oct 16, 2013

@forecho 我这边无论怎么修改都没法触发和你相同的错误,不过根据你给的错误信息应该是不能以multipart/form-data方式发送请求,那你可以尝试下在providers/OAuth2China_Provider_Abstract.php文件中的sendRequest方法里增加一个curl设置curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));

@forecho
Copy link
Author

forecho commented Oct 16, 2013

@tlikai string(85) "callback({"error":100004,"error_description":"param grant_type is wrong or lost "}); "

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants