2013-09-24 30 views
0
const CLIENT_ID    = '....'; 
const CLIENT_SECRET   = ''; 
const REDIRECT_URI   = 'http://localhost/myappli/web/app_dev.php/'; 
const AUTHORIZATION_ENDPOINT = 'http://example.com/'; 
const TOKEN_ENDPOINT   = 'http://example/index.php5/oauth/access_token'; 


/** 
* Connexion to API 
* 
* @return response 
*/ 
public function connexionAction() 
{ 
    $client = new Client(self::CLIENT_ID, self::CLIENT_SECRET); 

    if (!isset($_GET['code'])) 
    { 
     $authUrl = $client->getAuthenticationUrl(self::AUTHORIZATION_ENDPOINT, self::REDIRECT_URI); 
     return $this->redirect($authUrl); 
    } 
    else 
    { 
     $params = array('code' => $_GET['code'], 'redirect_uri' => self::REDIRECT_URI); 

     $infosConnexion = $client->getAccessToken(self::TOKEN_ENDPOINT, 'authorization_code', $params); 
     $accessToken = $infosConnexion['result']['access_token']; 
     $client->setAccessToken($accessToken); 

     $response = $client->fetch('http://example/index.php5/api/v3/user/infos'); 
     //var_dump($response);exit; 
    } 
} 

這是我的代碼連接到使用的oauth2爲了得到access_token使用它,然後連接到API的其他應用程序。「REDIRECT_URI」不使用OAuth2用戶端

但問題是驗證後我沒有重定向到我的應用程序(「http://localhost/myappli/web/app_dev.php/」)。

那麼如何將它重定向到我的應用程序以獲得access_token

回答

1

您是否在應用程序設置頁面中提供了相同的重定向uri?如果你指定關於你的應用程序(Facebook,Twitter等應用程序的類型),我可以更好地幫助你。

+0

你對我的應用程序設置頁面有什麼意義? – DOZ

+0

在創建應用程序時,您可能會要求提供您的網站網址和重定向網址。使用您在腳本中提供的內容檢查這些網址。 –

+0

謝謝你是這個問題!現在它工作了! – DOZ

相關問題