從twitter的api跳轉到Tumblr應該很容易。但事實證明,他們實際上並沒有以相同的方式實施oauth。儘管Twitter返回oauth_tokensecret,但並不要求您使用它來獲取訪問令牌。 Tumblr的確如此。現在創建了一個額外的步驟,因爲當用戶重定向到Tumblr登錄屏幕時,php會話將丟失。PHP存儲返回的oauth_secret
將返回的祕密令牌存儲在服務器端數據庫或客戶端Cookie中以進行檢索的主要做法是?
編輯1
使用Cookie我打了一個嗝。
Step 1. Send credential tokens of app.
Step 2. Receive as POST oauth_token and oauth_token_secret from Tumblr.
Step 3. Redirect user to Tumblr login using the oauth_token from Step 2.
Step 4. After login, Tumblr redirect back to my site with oauth_verifier.
Step 5. I submit the oauth_token_secret from step 2 and oauth_verifier from step 4.
Step 6. I receive access_token to users info.
第6步失敗,因爲我是從第1步第3步中輸給oauth_token_secret接入當我重定向到的tumblr的登錄頁面,我的兩個會話和餅乾超全局變量被清除。
從登錄
session_start();
if(!isset($_SESSION['secret'])){
echo "it's all gone!";
}
if(!isset($_COOKIE['tumblr_secret'])){
echo "it's all gone!";
}
SOLUTION
觀看了這些域的步驟3
//checked and verified that $tkns['oauth_token_secret'] has data
$_SESSION['secret']=$tkns['oauth_token_secret'];
setcookie('tumblr_secret',$tkns['oauth_token_secret'], time()+604800, '/');
session_write_close();
header("Location: http://www.tumblr.comoauthauthorize?oauth_token=".$tkns['oauth_token']);
exit();
代碼代碼上的回報。所有頁面都有www。在鏈接之前而不是一個。很簡單。
你應該存儲所有網站的會話,如果我沒有誤會,Twitter會生成一個你可以隨時使用的密鑰,並且你可以存儲在數據庫中。在Tumblr登錄後,API應重定向到您的頁面,並且您的會話變量爲 –
否,步驟如下:1.提交應用程序憑證標記 - >接收POST oauth_token和oauth_token _secret。 2.使用收到的oauth_token重定向到Tumblr登錄。 3.登錄後Tumblr返回GET oauth_token和oauth_verifier。 4.提交步驟1中的oauth_token_secret和步驟3中的oauth_verifier。但是,步驟2中的重定向會破壞php會話。 – user2782001