Facebook Graph API - 页面选项卡额外权限 [英] Facebook Graph API - Page Tab Extra Permissions

查看:300
本文介绍了Facebook Graph API - 页面选项卡额外权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的一个页面创建一个欢迎标签,但我希望能够访问喜欢的用户(权限user_likes)。



我只能找到关于Facebook 应用程序或集成Facebook的网站的方法的文档,我可以找到没有关于如何在Facebook 页面中的应用程序(标签)的文档(作为欢迎标签)。



可以通过页面标签向用户请求额外的权限,但允许页面访问没有它,还是一个案件或我必须提出一个应用程序以及一个页面选项卡?我可能会有一个按钮,当他们点击它授予页面额外的权限?



我正在尝试两个单独的实现,我都不能工作,PHP和$。

谢谢,






只需使用<

  $ loginUrl = $ fb-> getLoginUrl(
array('canvas'=> 1,'scope'= "'user_likes,user_about_me,user_birthday')
);

echo< a href ='$ loginUrl'>登录< / a>;

结果链接,只是将用户(页面iframe)重定向到屏幕, Facebook标志。我想要一个权限对话框!








使用JavaScript代码

 <脚本> 
FB.init({
appId:'APPID',
status:true,//检查登录状态
cookie:true,//启用Cookie以允许服务器访问会话
xfbml:true,//解析XFBML
oauth:true //启用OAuth 2.0
});

FB.login(function(response){
if(response.authResponse){
console.log('Welcome!Fetching your information ....');
FB.api('/ me',function(response){
console.log('Good to see you,'+ response.name +'。');
FB.logout函数(响应){
console.log('Logged out。');
});
});
} else {
console.log用户取消登录或未完全授权。');
}
},{scope:'email'});
< / script>

结果

 code>不安全的JavaScript尝试使用URL访问框架https://www.facebook.com/dialog/oauth?api_key=158609350887973&app_id=158609350887973&client_id=158609350887973&display=popup&locale=en_US&method=permissions .oauth&安培;来源= 1&安培; REDIRECT_URI = HTTP%3A%2F%2Fstatic.ak.fbcdn.net%2Fconnect%2Fxd_proxy.php%3Fversion%3D3%23CB%3Df2f7aed38%26origin%3Dhttp%253A%252F%url.com%252Ff3634c5da %26相关度%3Dopener%26transport%3Dpostmessage%26frame%3Df9748b77& response_type = token%2Csigned_request& scope = email& sdk = joey from frame with URL http://url.com/gs/index.php。域,协议和端口必须匹配。 






JavaScript还会打开以下错误弹出框








我的应用配置设置



解决方案

您的弹出窗口中看到错误,因为您的授权网址中的redirect_uri与您网站中列出的不符应用配置中的URL。要解决这个问题,您需要在应用配置中启用网站选项。通过点击网站旁边的复选框启用它,然后输入 http://Site.com (或任何您的真实网站url is)在站点URL文本框中。此网址必须与您在redirect_uri中提供的主机网址相匹配。这样做应该会解决弹出窗口错误。



根据不安全的JavaScript尝试访问框架错误,您是否使用Webkit浏览器? Webkit抛出这些错误,但大部分可以忽略。有关详细信息,请参阅:不安全的JavaScript尝试使用网址访问框架...在Chrome Webkit检查器中不断生成错误


I am trying to create a welcome tab for one of my pages, but I would like to be able to access a users likes (permission user_likes).

I can only find documentation on how to do this for a Facebook app or a website integrating Facebook, I can find no documentation on how to do this for an app (tab) inside a facebook page (as a welcome tab).

Is it possible as a page tab to request extra permissions from the user but allow page access without it, or is it a case or me having to make an application as well as a page tab? Could I perhaps have a button that when they click it grants the page extra permissions?

I am currently trying two separate implementations, neither of which I can get to work, PHP and Javascript.

Thanks,


Just using

$loginUrl = $fb->getLoginUrl(
     array('canvas' => 1, 'scope' => 'user_likes,user_about_me,user_birthday')
);

echo "<a href='$loginUrl'>Login</a>";

Results in a link, which just redirects the user (within the pages iframe) to a screen with the Facebook logo. I want a permissions dialog!


Using the javascript code

<script>
  FB.init({
    appId  : 'APPID',
    status : true, // check login status
    cookie : true, // enable cookies to allow the server to access the session
    xfbml  : true, // parse XFBML
    oauth  : true // enable OAuth 2.0
  });

 FB.login(function(response) {
   if (response.authResponse) {
     console.log('Welcome!  Fetching your information.... ');
     FB.api('/me', function(response) {
       console.log('Good to see you, ' + response.name + '.');
       FB.logout(function(response) {
         console.log('Logged out.');
       });
     });
   } else {
     console.log('User cancelled login or did not fully authorize.');
   }
 }, {scope: 'email'});
</script>

Results in

Unsafe JavaScript attempt to access frame with URL https://www.facebook.com/dialog/oauth?api_key=158609350887973&app_id=158609350887973&client_id=158609350887973&display=popup&locale=en_US&method=permissions.oauth&origin=1&redirect_uri=http%3A%2F%2Fstatic.ak.fbcdn.net%2Fconnect%2Fxd_proxy.php%3Fversion%3D3%23cb%3Df2f7aed38%26origin%3Dhttp%253A%252F%url.com%252Ff3634c5da%26relation%3Dopener%26transport%3Dpostmessage%26frame%3Df9748b77&response_type=token%2Csigned_request&scope=email&sdk=joey from frame with URL http://url.com/gs/index.php. Domains, protocols and ports must match.


The javascript also opens the following error popup box


My app config settings

解决方案

You're seeing the error in your popup window because the redirect_uri in your authorization URL doesn't match what's listed in your Site URL in app config. To address this, you need to enable the "Website" option in app config. Enable it by clicking on the checkbox next to "Website" and then enter http://Site.com (or whatever your real site url is) in the "Site URL" text box. This URL must match the host url you're providing in redirect_uri. Doing this should solve the popup window error.

In terms of the "Unsafe JavaScript attempt to access frame" error, are you using a webkit browser? Webkit throws these errors but for the most part can be ignored. See this for more info: "Unsafe JavaScript attempt to access frame with URL..." error being continuously generated in Chrome webkit inspector

这篇关于Facebook Graph API - 页面选项卡额外权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆