开发者

Making Graph API calls within Tab application using PHP

I'm trying to create a Facebook tab application that can display a permissions dialog in the same it would work for a Facebook Connected website. I was hoping that for tab applications, housed within an iframe, the process would be the same if not very similar.

This is how I currently generate my log in URL:

$params = array(
    '开发者_开发技巧canvas' => 1,
    'redirect_uri' => 'http://mysite.com/next_step",
    'scope' => 'email,user_about_me',
);

$login_url = $facebook->getLoginUrl( $params );

This creates a log in URL which, when clicked, basically triggers a Facebook log in dialog if the user isn't already logged in and subsequently a permissions dialog if the user hasn't granted permissions for my application yet. This technique works flawlessly within the context of a website.

When I do this from within a Facebook housed iframe however, I get either the following result:

When a user hasn't accepted the permissions yet, after clicking the log in url, the user is redirected to a page within the iframe that simply displays a Facebook logo in the top left corner. Clicking the logo breaks the user out of the iframe and displays the permissions dialog. From that point on, the user is no longer in the iframe.

How can I make everything stay within the iframe and how can make it so that the page with the Facebook logo isn't shown?


Why you don't use the login dialog ?

https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=email,read_stream

You can read more how to use it: http://developers.facebook.com/docs/authentication/

Here is example:

I created application with AppID: 2785870588**573 & Canvas URL: www.mysite.com

To be able to ask for permissions I can use the link above like:

.https://www.facebook.com/dialog/oauth?client_id=2785870588**573&redirect_uri=www.mysite.com&scope=email,read_stream

or like you did:

...    
$login_url = $facebook->getLoginUrl( $params );

(both methods should result the same URL)

Once i have the URL constructed properly I create HTML link. In my application code I can use simply:

<a target="_top" href="https://facebook.com/dialog/oauth?
    client_id=2785870588**573&
    redirect_uri=www.mysite.com&
    scope=email,read_stream">Login</a>

The important here is target="_top" which tells Facebook to load the login link in the parent frame and not inside your application. That way you will not get the Facebook logo.

Here is working example if it helps: http://apps.facebook.com/278587058833573/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜