English 中文(简体)
如何使用Facebook OAuth 2.0认证像Zynga和其他人一样使用它?
原标题:How to use Facebook OAuth 2.0 authentication like Zynga and other use it?

当用户输入http://apps.facebook.com/myfancyappFacebook身份验证文档非常清楚URL的外观

https://graph.facebook.com/oauth/authorize?client_id=[APPID]&redirect_uri=http://www.myfancyapp.com/&scope=user_photos,user_videos,publish_stream

将此URL直接粘贴到浏览器中可以正常工作。我想要的是通过JavaScript(或其他东西)从应用程序URL重定向用户

http://apps.facebook.com/myfancyapp

到上面的验证框URL。

我以为这样会奏效:

   <script type="text/javascript">
   <!--
      window.location = "https://graph.facebook.com/oauth/authorize?client_id=[APPID]&redirect_uri=http://www.myfancyapp.com/&scope=user_photos,user_videos,publish_stream"
   //-->
   </script>

这将我重定向到一个正文如下的页面

单击图像/测试,然后重定向到身份验证框。

如何直接重定向到“请求权限”框。我知道它在某种程度上和其他开发者(例如Zynga)一样有效。

最佳回答

我正在做与询问者相同的事情,只是使用top.location代替window.location。href=“https://graph.....”

喜欢:

<script type="text/javascript">
top.location.href = "https://graph.facebook.com/oauth/authorize?client_id=[APPID]&scope=email&redirect_uri=http://apps.facebook.com/myfancyapp/";
</script>

如果需要,提示登录,然后提示权限。然后重定向到应用程序。

问题回答

用PHP做这件事很容易。

在后端

$facebook = new Facebook( array(
     appId   =>  <FB_APP_ID> 
  ,  secret  =>  <FB_APP_SECRET> 
  ,  cookie  => true
));

$fbSession = $facebook->getSession();
if ( !$fbSession )
{
  $url = $facebook->getLoginUrl( array(
       canvas      => 1
    ,  fbconnect   => 0
    ,  display     =>  page 
    ,  cancel_url  => null
    ,  req_perms   =>  user_photos,user_videos,publish_stream 
  ) );
}

然后,在前端

<script type="text/javascript">
  top.location.href =  <?php echo $url; ?> ;
</script>
<p>
Not being redirected? <a href="<?php echo $url; ?>" target="_top">Click Here.</a>
</p>




相关问题
How to use redirect_to to a non-Rails URL with query params?

We just had an existing use of redirect_to break due to a Rails upgrade, and it led to a question. I ve been experimenting, and I don t seem to find a way to use redirect_to to send the user to a non-...

Apache authentication: Redirect on failure, reliably?

I ve set my ErrorDocument 401 to point to my website s account creation page, but not all browsers seem to honor this redirect (Safari). Also, other browsers (Firefox, Chrome) never quit asking for ...

Response.Redirect HTTP status code

Why is it that ASP/ASP.NET Response.Redirect uses a HTTP-302 status code ("Moved Temporarily") even though in most cases a HTTP-301 status code ("Moved Permanently") would be more appropriate?

Exceptions: redirect or render?

I m trying to standardize the way I handle exceptions in my web application (homemade framework) but I m not certain of the "correct" way to handle various situations. I m wondering if there is a ...

Cakephp is not redirecting properly when pages are cached

I am having some issues with a site that was working correctly until i implemented full page caching in CakePHP. I have followed the guidance in the Manual and have my $session->flash in a no-cache ...

热门标签