将Timeline应用程序授权给用户的配置文件,然后执行OpenGraph操作

时间:2012-03-11 04:50:55

标签: javascript facebook authentication facebook-graph-api dialog

我对Facebook开发很新,所以一直试着阅读较旧的问题,但仍然有点丢失= \

这是我正在努力的一个:

目前,我有一个应用程序,其中包含多个已定义的Open Graph操作,即“提出问题”。有没有办法为没有应用程序的用户提供一个对话框,以便在他们授权应用程序后,它会继续执行OG操作?理想情况下,它会顺利进行,没有多个对话框。

OG行动:

FB.api(
    "/me/beta_sandbox:ask?question=http://example/question/1",
    'post',
    function(response) {
    if (!response || response.error) {
        alert('Sorry, your question was not shared: '+response.error);
    } else {
        alert('Your question was successfully shared!');
    }
});

解决方案:重定向uri?

非常感谢任何帮助=)

1 个答案:

答案 0 :(得分:0)

您应该在发布操作之前授权用户。

您可以在FB.getLoginStatus方法中嵌套发布操作以发布已登录用户的操作,并为未与应用程序关联或退出Facebook的用户启用登录对话框:

var publishAction = function(){
  FB.api('/me/beta_sandbox:ask?question=http://example/question/1', 'post',
    function(response) {
      if (!response || response.error) {
        console.log('question was not shared', response);
      } else {
        console.log('question was successfully shared!');
      }
    }
  );
}

FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
    // User is authenticated, Publish Action
    publishAction();
  } else {
    // Bring Login Dialog to authenticate the user
  }
}

您还可以利用FB.login方法在用户登录后发布操作(对于已经登录对话框的用户不会立即打开和关闭,并且将调用回调):

FB.login(function(response) {
  if (response.authResponse) {
    // User is authenticated, Publish Action
    publishAction();
  } else {
    // User declined authentication
  }
});