[教學] Facebook API權限開放教學,Facebook API for PHP login url premission

[教學] Facebook API PHP SDK – 基本篇,已經提到基本的 Facebook 觀念,如果需要取得更多資料呢?例如,使用者Email, 貼資料在牆上, 取得朋友列表…等,都需要在使用者登入的時候,就按下允許。

## **參考資料**
- [Facebook API權限介紹](http://developers.facebook.com/docs/authentication/permissions/) - [權限需求對照表](http://developers.facebook.com/docs/reference/api/user/)
**** ## **參數說明**
** **
`$login_url = $facebook->getLoginUrl(array(

'fbconnect' => 1,

'canvas' => 0,

'next' => 'http://localhost/demo/facebook/index.php',

'redirect_uri' => 'http://localhost/demo/facebook/index.php',

));

` 參數說明: fbconnect:Facebook 連線,恆為1。 canvas:Facebook內的畫布,沒有用到,為0。 next:按下完成後轉向網址。 redirect_uri:下一頁轉向網址。 基本款權限如下圖
[![](http://3.bp.blogspot.com/-CjhsVZTcSrc/TcFr-tzqgqI/AAAAAAAALfE/msPWXOOycys/s1600/2011-05-04_230832.jpg)](http://3.bp.blogspot.com/-CjhsVZTcSrc/TcFr-tzqgqI/AAAAAAAALfE/msPWXOOycys/s1600/2011-05-04_230832.jpg)
## 修改參數
`$login_url = $facebook->getLoginUrl(array(

'fbconnect' => 1,

'canvas' => 0,

'req_perms' => 'email,publish_stream',

'next' => 'http://localhost/demo/facebook/index.php',

'redirect_uri' => 'http://localhost/demo/facebook/index.php',

));

` 加入**req_perms **= **email, publish_stream**權限之後,登入權限會變成,如下圖
[![](http://1.bp.blogspot.com/-AMYya1UNSjQ/TcFssX_neEI/AAAAAAAALfI/uZNQnvfzUaw/s1600/2011-05-04_231151.jpg)](http://1.bp.blogspot.com/-AMYya1UNSjQ/TcFssX_neEI/AAAAAAAALfI/uZNQnvfzUaw/s1600/2011-05-04_231151.jpg)
沒錯,如此一來就可以擁有操控權限,是不是非常的容易呢!?原始碼,自己拉回去改。 `
require './facebook.php';

$facebook = new Facebook(array(

'appId' => 'yor key',

'secret' => 'your key',

'cookie' => true,

));



$login_url = $facebook->getLoginUrl(array(

'fbconnect' => 1,

'canvas' => 0,

'req_perms' => 'email,publish_stream',

'next' => 'http://localhost/demo/facebook/index.php',

'redirect_uri' => 'http://localhost/demo/facebook/index.php',

));

?>

Renew a facebook Login URL.







`

CaesarChi

Web developer, focus on website fullstack, special JavaScript, and love sharing developing experience and communicate with developers. http://about.me/clonn