我利用出色的tmhOAuth PHP库为我的网站。然而,我不能'弄清楚如何访问从我auth.php收到的用户令牌/秘密? (说,当试图获取当前用户的好友列表)如何使用我从tmhOAuth获得的用户令牌/密码?
它在the example的陈述的:
* Although this example uses your user token/secret, you can use
* the user token/secret of any user who has authorised your application.
我已经成功地利用了auth.php example的,但如何利用用户令牌的/我收到的秘密?如示例,它只是说,像这样:
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => 'YOUR_CONSUMER_KEY',
'consumer_secret' => 'YOUR_CONSUMER_SECRET',
'user_token' => 'A_USER_TOKEN',
'user_secret' => 'A_USER_SECRET',
));
显然,硬编码不会为我工作,所以,简单地说,我不知道是在当前登录用户的令牌/秘诀是什么?
这是一个存储的凭据的例子,我相信:
// already got some credentials stored?
} elseif (isset($_SESSION['access_token'])) {
$tmhOAuth->config['user_token'] = $_SESSION['access_token']['oauth_token'];
$tmhOAuth->config['user_secret'] = $_SESSION['access_token']['oauth_token_secret'];
$code = $tmhOAuth->request('GET', $tmhOAuth->url('1/account/verify_credentials'));
if ($code == 200) {
$resp = json_decode($tmhOAuth->response['response']);
echo $resp->screen_name;
} else {
outputError($tmhOAuth);
}
耶,大多数这种流动是由tmhOAuth(感激)照顾。但我欣赏破败!但是,我不知道如何传递变量(我已经存储在$ _SESSION我相信 - 看看编辑!)所以,首先:如何传递$ _SESSION变量到上面的代码? – knutole
您可以用$ _SESSION ['user_token']替换'user_token',或者在您的结尾调用该变量。秘密一样。所以, 'user_token'=> $ _SESSION [ 'ACCESS_TOKEN'] [ '的oauth_token'], 'user_secret'=> $ _SESSION [ 'ACCESS_TOKEN'] [ 'oauth_token_secret'] –
很显然,我试过了,但我有不好调试的情况下, !谢谢harald! – knutole