Facebook API &OAUTH - 在显示应用程序之前请求权限 [英] Facebook API & OAUTH - Request Permission before displaying app
问题描述
我安装了一个 facebook 应用程序并且运行良好.我想做的是添加请求用户权限数据的功能.例如 - read_friendlists,user_groups,email,user_birthday,status_update,publish_stream,
I have a facebook app installed and working great. What I would like to do is add in the functionality of requesting user permission data. such as - read_friendlists,user_groups,email,user_birthday,status_update,publish_stream,
首先,这里是检查我们的 facebook 时间线应用程序上是否有粉丝或没有粉丝的代码.
Firstly here is the code that checks if a fan or none fan is on our facebook timeline app.
// If a fan is on your page
if ($like_status) {
$a = file_get_contents("http://www.domain.com/home.php");
echo ($a);
}
else {
// If a non-fan is on your page
$a = file_get_contents("http://www.domain.com/home.php");
echo ($a);
}
我想做的是,如果我们的页面上没有粉丝,请打开 Facebook 请求权限并设置一些权限.然后将它们重定向到//如果我们的页面上有粉丝.
What I would like to do, is, if a none fan is on our page, open a facebook request for permission and set a number of permissions. Then redirect them to the // if a fan is on our page.
我已经很好地浏览了这里,但我仍然不清楚如何设置请求"权限页面.任何帮助将不胜感激
I have had a good look around here but I am still not clear how to setup the "request" for permission page. Any help would be greatly appreciated
推荐答案
您可以通过两种方式做到这一点..
you can do this in two ways..
1) 通过设置url在页面中打开oauth对话框
1) Open oauth dialog in page by setting the url
var oauth_url = 'https://www.facebook.com/dialog/oauth/';
oauth_url += '?scope=email,user_birthday,user_location,user_about_me,user_likes';
oauth_url += '&client_id=' + appid;
oauth_url += '&redirect_uri=' + encodeURIComponent('https://www.facebook.com/pages/' + appname + '/' + pageId + '/?sk=app_' + appid);
window.top.location = oauth_url;
2) 或者您可以在弹出窗口中打开 oauth 对话框:
2) Or you can open the oauth dialog in popup:
FB.login(function(loginResponse) {
if (loginResponse.authResponse) {
var userId = loginResponse.authResponse.userID;
}
else {
//'User cancelled login or did not fully authorize.
}
}, { scope: 'email,user_birthday,user_location' });
这篇关于Facebook API &OAUTH - 在显示应用程序之前请求权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!