Javascript 如何设置在墙上张贴消息的权限对话框
我已经在Facebook上创建了一个应用程序。通过使用FacebookJavaScriptSDK,我将来自android phonegap应用程序的消息发布到FacebookWall。但我想在消息发布到墙上之前显示权限对话框 (即)当我单击权限对话框中的“允许”按钮时,消息应张贴在墙上,而当我单击“不允许”按钮时,消息不应张贴在墙上。 我的代码是:Javascript 如何设置在墙上张贴消息的权限对话框,javascript,facebook,cordova,Javascript,Facebook,Cordova,我已经在Facebook上创建了一个应用程序。通过使用FacebookJavaScriptSDK,我将来自android phonegap应用程序的消息发布到FacebookWall。但我想在消息发布到墙上之前显示权限对话框 (即)当我单击权限对话框中的“允许”按钮时,消息应张贴在墙上,而当我单击“不允许”按钮时,消息不应张贴在墙上。 我的代码是: <body> <div id='fb-root'></div> <script src='all.js'&
<body>
<div id='fb-root'></div>
<script src='all.js'></script>
<input type="text" value="User ID" name="user_ids" />
<p><a onclick='postToFeed(); return false;'>Post to Feed</a></p>
<p id='msg'></p>
<script>
FB.init({appId: "xxxxxxxx", status: true, cookie: true});
function postToFeed()
{
var user_ids = document.getElementsByName("user_ids")[0].value;
alert(user_ids);
FB.api('/me/feed', 'post', { message: user_ids}, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
}
</script>
</body>
投递
init({appId:“xxxxxxxx”,状态:true,cookie:true});
函数postToFeed()
{
var user_id=document.getElementsByName(“user_id”)[0]。值;
警报(用户标识);
api('/me/feed',post',{message:user_id},函数(响应){
如果(!response | | response.error){
警报(“发生错误”);
}否则{
警报('Post ID:'+response.ID);
}
});
}
上述代码托管在服务器上。在phonegap(index.html)中,我使用window.open方法调用了url,它将显示文本框和按钮。当我点击按钮时,(从文本框中获取值),消息应该贴在墙上
如何设置此编码的权限对话框或如何在FB.api('/me/feed')中传递{perms:'publish_stream'}
请给我一些建议/想法
提前谢谢。我不知道你的问题是否正确,但我建议: 首先请求许可,然后在下一步中显示“发送”按钮或自动发送帖子-无论您想要什么。不是两者同时发生(我只是不明白这个概念)。下面是一些可能对您有所帮助的代码:
window.fbAsyncInit = function() {
FB._https = true;
FB.init({
appId : 'APP_ID',
status : true,
cookie : true,
oauth : true
});
// Check whether the user is connected to the app
FB.getLoginStatus(function(response) {
if (response.status !== 'connected') {
// The user has not authorized the app
authorizeApp();
} else {
// The user has already authorized the app
var fbuid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
FB.api('/me', function(response) {
// Check for publish_stream extended permission
var query = FB.Data.query('select publish_stream from permissions where uid={0}', fbuid);
query.wait(function(rows) {
if(rows[0].publish_stream == 1) {
// The user has granted the extended permission
postToWall();
} else {
// The user has not granted the extended permission
authorizeApp();
}
});
});
}
});
};
(function() {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol + '//connect.facebook.net/de_DE/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
function authorizeApp() {
// Redirect the user back after authorization
var path = 'https://www.facebook.com/dialog/oauth?';
var queryParams = ['client_id=APP_ID', 'redirect_uri=REDIRECT_URI', 'response_type=token', 'scope=publish_stream'];
var query = queryParams.join('&');
var url = path + query;
top.location.href = url;
}
// OR
function authorizeAppInPopup() {
FB.login(function(response) {
if (response.authResponse) {
// User authorized app
postToWall();
} else {
// User cancelled login or did not fully authorize
}
}, {scope: 'publish_stream'});
}
谢谢先生谢谢你的答复。如何获取文本框值并将其传递给FB.api('/me/feed/','post',{message:'},fuuction(res){});在FB.login函数中,我的代码第一次工作正常,下次它将显示出错。请告诉我solutionhai,我的服务器名是。现在,我在phonegap应用程序的服务器上托管代码,并使用window.open方法调用该url。在我的logcat中显示错误:不安全的javascript试图使用url访问帧file://.../ 从带有url的框架。如何解决此问题。如何使用phonegap应用程序打开该url