我利用出色的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