开发者

Get users' authorization to run my application and access their full name

How do I get users' authorization to run my application and access their full name any time I need it? The following is a file included on top of all my application files. In reality, it don't even ask for users' authorization to run as other applications do (l开发者_JAVA百科ike CittyVille and others).

<?php
include_once 'facebook/facebook.php';

$facebook = new Facebook(array(
  'appId' => 'APPID',
  'secret' => 'APPSECRET'
));

$user = $facebook->getUser();

if($user)
{
  try
  {
    $me = $facebook->api('/me?fields=id,name,locale');
  }
  catch(FacebookApiException $e)
  {
    error_log($e);
    $user = null;
  }
}

if($user)
  $logoutUrl = $facebook->getLogoutUrl();
else
  $loginUrl = $facebook->getLoginUrl();

Can anyone say me the right way for doing the request?


Ill answer this because I think the documentation for the PHP API is, well non existent and the example they give you, which is what you are using, isn't that great. Though I do think a few moments of Google-ing would of given you the answer.

You are correct, it is not logging the user in.

It is however checking to see if the user is logged in already, which if it is is getting the users profile information and generating a link to logout.

If the user is not logged in it is generating a link the user will need to click on in order to log in to your site, and give your site permissions to access the account.

As far as what permissions your application requires, you need to put that information in the ->getLoginUrl() call so that facebook knows what permissions you require. You can find information on the permissions you can pass at http://developers.facebook.com/docs/reference/api/permissions/

Once the person has clicked on the link generated, it takes them to facebook, asks them to login and grant your website permissions, then redirects either back to the page it came from, or to another page (depending on what you tell it in the getLoginUrl call). At this point a user is now logged in to your site, and you can run use the API to get information.

Alternately, once you have the address they need to go to in order to log in, you can use php's header function to redirect them to this page without them having to actually click the a link.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜