2014-01-06 4 views
0

내 앱으로 오래 거주 한 액세스 토큰을 받고 사용자 테이블에 저장하고 싶습니다. 나중에 다시 사용할 수 있습니다. 내가이 호출 만들고있어 :Facebook 장기 보관 토큰 저장/저장

$urlLongLiveToken = "https://graph.facebook.com/oauth/access_token? 
client_id=xxxxxx&client_secret=yyyyyy&grant_type=fb_exchange_token 
&fb_exchange_token=zzzzzzzzz"; 

$facebook->api($urlLongLiveToken); 

교환 토큰 (zzzzzz입니다 것은) 변수 "코드"입니다 나는 페이스 북에 첫 번째 호출에서 얻을 :

$facebook->getLoginUrl(array('scope' => 'publish_stream')); 

긴 살았의 API 호출 토큰이 배열을 반환합니다.

array(17) { 'about' => string(108) "OAuth is a simple way to publish and interact with 
protected data. Learn more about OAuth: http://oauth.net/" 'awards' => string(160) "• 
CNET Webware 100 award in the Editors’ Choice Most Important Technology category • Best 
New/Improved Standard in IAM & GRC, European Identity Conference" 'can_post' => 
bool(true) 'category' => string(17) "Internet/software" 'description' => string(174) 
"OAuth is a simple way to publish and interact with protected data. It's also a safer 
and more secure way for people to give you access. We've kept it simple to save you 
time." 'founded' => string(4) "2007" 'is_published' => bool(true) 'mission' => 
string(1344) "In developing OAuth, we sought to invent as little as possible, following 
the Microformats approach to pave existing cowpaths and relying on conventions already 
established in protocols like Google’s AuthSub, aol’s OpenAuth, Yahoo’s BBAuth and 
FlickrAuth and Facebook’s FacebookAuth. While we wanted the best protocol we could 
design, we also wanted one that people would use and that would be compatible with 
existing authentication methods, inherit from existing RFCs and reuse web standards 
wherever "... 'products' => string(19) "OAuth 1.0 OAuth 2.0" 'talking_about_count' => 
int(49) 'username' => string(5) "oauth" 'website' => string(17) "http://oauth.net/" 
'were_here_count' => int(0) 'id' => string(11) "xxxxxxxxxxxx" 'name' => string(5) 
"OAuth" 'link' => string(30) "https://www.facebook.com/oauth" 'likes' => int(7165) } 

무엇이 잘못 되었습니까? 오래 살아있는 토큰을 어떻게 얻을 수 있습니까?

답변

0

전체 Facebook 그래프 API URL을 "api"함수에 전달하면 안됩니다. "/ oauth/access_token? etc"만 전달하면됩니다.

전체 URL을 전달하면 실제 HTTP 요청을 https://graph.facebook.com/https://graph.facebook.com/oauth/에게 전송하기 때문입니다.

그래서 :

<?php 
    $urlLongLiveToken = "/oauth/access_token?client_id=xxxxxx&client_secret=yyyyyy&grant_type=fb_exchange_token&fb_exchange_token=zzzzzzzzz"; 
    $facebook->api($urlLongLiveToken) 
?> 
+0

, 감사합니다 더 나은 것 같다하지만 지금은 "잘못된 토큰"문제가 있습니다. –

+0

"코드"에서 짧은 거주 액세스 토큰을 얻은 다음 그 액세스 토큰을 사용하면 오래 살 수 있다고 생각합니다. 로그인 흐름에 대한 자세한 내용은 [여기] (https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow)를 참조하십시오. –

+0

예, 실제로 불필요한 전화를 걸었습니다. 페이스 북 SDK는 $ fb-> setExtendedAccessToken()과 같은 간단한 메소드를 제공합니다. –