使用Facebook Open Graph发布故事时的OAuthException

时间:2013-07-02 20:03:59

标签: facebook facebook-javascript-sdk facebook-opengraph facebook-oauth

我在使用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}

怎么了?

1 个答案:

答案 0 :(得分:0)

您在传递给app的JavaScript对象中使用了FB.api作为属性名称:

        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'}
                },