使用Facebook Open Graph发布故事时的OAuthException(OAuthException when posting story with Facebook Open Graph

编程入门 行业动态 更新时间:2024-10-28 20:21:30
使用Facebook Open Graph发布故事时的OAuthException(OAuthException when posting story with Facebook Open Graph)

我在使用Open Graph在Facebook上发布我的第一个故事时遇到了问题。 我在OrionHub开了一个网站。 这是我的代码:

我已经创建了一个动作和一个对象。

的index.html

<!DOCTYPE html> <html> <head> <meta charset=utf-8 /> <meta property="fb:app_id" content="APP_ID" /> <meta property="og:type" content="pruebablackbear:app" /> <meta property="og:url" content="http://facebookapp.orionhub.org:8080/index.html" /> <meta property="og:title" content="Sample app" /> <meta property="og:image" content="https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <title>My Facebook App</title> </head> <body> <div id="fb-root"></div> <script> window.fbAsyncInit = function() { // init the FB JS SDK FB.init({ appId : '124306291113571', // App ID from the app dashboard channelUrl : '//facebookapp.orionhub.org:8080/index.html', // Channel file for x-domain comms status : true, // Check Facebook Login status xfbml : true // Look for social plugins on the page }); // Additional initialization code such as adding Event Listeners goes here }; // Load the SDK asynchronously (function(d, s, id){ var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/all.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); </script> <h2 class="saludo">HELLO </div> <button class = 'loginButton'> Press me to Login </button> <button class = 'publiSH'> Publicar una historia </button> <script src="main.js"></script> </body> </html>

main.js

$('.loginButton').click(function(){ // FACEBOOK LOGIN FB.login(function(response) { // GETTING FACEBOOK DATA FB.api('/me', function(response) { // stuff you want to happen after getting data goes here // alert(response.name); // console.log(response); $(".saludo").append(response.name); }); //FB.api // END - FACEBOOK DATA },{scope: 'publish_actions'}); //FB.login // END - FACEBOOK LOGIN }); //click $('.publish').click(function(){ FB.getLoginStatus( function(response){ // alert(response.status); if(response.status=="connected"){ //stuff to happen after click goes here. E.g. FB.api( 'me/objects/pruebablackbear:app', 'post', { app:"http://facebookapp.orionhub.org:8080/index.html", privacy:{'value': 'SELF'} }, function(response) { // handle the response if (!response || response.error) { alert(JSON.stringify(response.error)); alert('Error Occurred ' + response.responseText + " " + response.error.responseText); } else { alert('Published: ' + response.id); } } ); window.open('http://www.google.com','mywindow','width=400,height=200'); }else{ alert("Please Login"); } } ); }); //click

我可以正确登录,但是当我尝试发布故事时,我收到了以下消息:

{"message":"(#100) The parameter object is required","type":"OAuthException","code":100}

怎么了?

I´m having a problem posting my first story on Facebook with the Open Graph. I started a site at OrionHub. This is my code:

I have already created an action and an object.

index.html

<!DOCTYPE html> <html> <head> <meta charset=utf-8 /> <meta property="fb:app_id" content="APP_ID" /> <meta property="og:type" content="pruebablackbear:app" /> <meta property="og:url" content="http://facebookapp.orionhub.org:8080/index.html" /> <meta property="og:title" content="Sample app" /> <meta property="og:image" content="https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <title>My Facebook App</title> </head> <body> <div id="fb-root"></div> <script> window.fbAsyncInit = function() { // init the FB JS SDK FB.init({ appId : '124306291113571', // App ID from the app dashboard channelUrl : '//facebookapp.orionhub.org:8080/index.html', // Channel file for x-domain comms status : true, // Check Facebook Login status xfbml : true // Look for social plugins on the page }); // Additional initialization code such as adding Event Listeners goes here }; // Load the SDK asynchronously (function(d, s, id){ var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/all.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); </script> <h2 class="saludo">HELLO </div> <button class = 'loginButton'> Press me to Login </button> <button class = 'publiSH'> Publicar una historia </button> <script src="main.js"></script> </body> </html>

main.js

$('.loginButton').click(function(){ // FACEBOOK LOGIN FB.login(function(response) { // GETTING FACEBOOK DATA FB.api('/me', function(response) { // stuff you want to happen after getting data goes here // alert(response.name); // console.log(response); $(".saludo").append(response.name); }); //FB.api // END - FACEBOOK DATA },{scope: 'publish_actions'}); //FB.login // END - FACEBOOK LOGIN }); //click $('.publish').click(function(){ FB.getLoginStatus( function(response){ // alert(response.status); if(response.status=="connected"){ //stuff to happen after click goes here. E.g. FB.api( 'me/objects/pruebablackbear:app', 'post', { app:"http://facebookapp.orionhub.org:8080/index.html", privacy:{'value': 'SELF'} }, function(response) { // handle the response if (!response || response.error) { alert(JSON.stringify(response.error)); alert('Error Occurred ' + response.responseText + " " + response.error.responseText); } else { alert('Published: ' + response.id); } } ); window.open('http://www.google.com','mywindow','width=400,height=200'); }else{ alert("Please Login"); } } ); }); //click

I can log in correctly, but when I try to publish a story I get this message:

{"message":"(#100) The parameter object is required","type":"OAuthException","code":100}

What's wrong?

最满意答案

您已将传递给FB.api的JavaScript对象中的app用作属性名称:

FB.api( 'me/objects/pruebablackbear:app', 'post', { app:"http://facebookapp.orionhub.org:8080/index.html", privacy:{'value': 'SELF'} },

但这似乎是您的操作的名称 - 该参数必须使用与您执行操作的对象相同的名称。

因此,如果您的对象名为banana ,那么它将是:

FB.api( 'me/objects/pruebablackbear:app', 'post', { banana:"http://facebookapp.orionhub.org:8080/index.html", privacy:{'value': 'SELF'} },

编辑:我认为它应该是这样的:

FB.api( 'me/pruebablackbear:crear', 'post', { app: 'http://facebookapp.orionhub.org:8080/index.html', privacy: {value: 'SELF'} },

You have used app as property name in the JavaScript object that you pass to FB.api:

FB.api( 'me/objects/pruebablackbear:app', 'post', { app:"http://facebookapp.orionhub.org:8080/index.html", privacy:{'value': 'SELF'} },

but that seems to be the name of your action - the parameter must use the same name that the object you are performing the action upon is called.

So if your object was named banana, it would be:

FB.api( 'me/objects/pruebablackbear:app', 'post', { banana:"http://facebookapp.orionhub.org:8080/index.html", privacy:{'value': 'SELF'} },

Edit: I think that’s what it should look like:

FB.api( 'me/pruebablackbear:crear', 'post', { app: 'http://facebookapp.orionhub.org:8080/index.html', privacy: {value: 'SELF'} },

更多推荐

本文发布于:2023-07-27 15:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1292459.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:故事   Graph   Open   Facebook   posting

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!