已迁移到 Facebook Graph API - 应用程序现已损坏 - 无法发布到墙上

发布于 2024-09-08 02:17:15 字数 2503 浏览 2 评论 0原文

昨天我更改了应用程序设置并启用了“新数据权限”和“新 SDK”。

此后向用户墙发布消息的功能停止工作。在我的网站上,用户使用 facebook API(图)登录并能够在他们的墙上发布消息。

这是我的旧代码,运行良好:

function publish_with_permission(permission,action_links,attachment) {
  FB.ensureInit(function() {
    FB.Connect.requireSession(function(){
        //check is user already granted for this permission or not
        FB.Facebook.apiClient.users_hasAppPermission(permission,
        function(result) {
            // prompt offline permission
            if (result == 0) {
                // show the facebook permission dialog
                FB.Connect.showPermissionDialog(permission,
                function(result){
                    if (!result) {
                       FB.Connect.streamPublish('', attachment, action_links, null, "Post this:", jscallback);
                    } else {
                    // permission granted, post without facebook dialog
                       FB.Connect.forceSessionRefresh(function() {
                       FB.Connect.streamPublish('', attachment, action_links, null, "Post this:", jscallback,true);
                    });
                }
            }, true, null);
        } else {
            // permission already granted, post suddenly
            // without facebook dialog
            FB.Connect.streamPublish('', attachment, action_links, null, "Post this:", jscallback,true);
            }
        });
    });
});
}

该函数只是挂起,没有任何反应。我在这个论坛上搜索并找到了这个 post

function fb_publish() {
     FB.ui(
       {
         method: 'stream.publish',
         message: 'Message here.',
         attachment: {
           name: 'Nom ici.',
           caption: 'Caption here.',
           description: (
             'description here'
           ),
           href: 'url here'
         },
         action_links: [
           { text: 'Code', href: 'action url here' }
         ],
         user_prompt_message: 'Personal message here'
       },
       function(response) {
         if (response && response.post_id) {
           alert('Post was published.');
         } else {
           alert('Post was not published.');
         }
       }
     );  
  }

这个可行,但有两个问题 1) 即使当用户第一次使用图形 API 登录并且他们已授予发布到他们的墙的扩展权限时,此方法每次都会询问用户是否允许 - 前一个方法没有这样做。 2)此方法还允许用户添加他们的评论 - 我也不想要这个。

我想无缝地发布到墙上,而无需再次明确请求许可,因为他们之前已经授予了许可。

我正在使用 PHP - 任何提示将不胜感激 谢谢

Yesterday I changed the application settings and enabled "New Data Permissions" and "New SDKs".

After that the feature of posting message to the users wall stopped working. On my website, users login using facebook API (Graph) and are able to post messages on their wall.

This is my old code that was working fine:

function publish_with_permission(permission,action_links,attachment) {
  FB.ensureInit(function() {
    FB.Connect.requireSession(function(){
        //check is user already granted for this permission or not
        FB.Facebook.apiClient.users_hasAppPermission(permission,
        function(result) {
            // prompt offline permission
            if (result == 0) {
                // show the facebook permission dialog
                FB.Connect.showPermissionDialog(permission,
                function(result){
                    if (!result) {
                       FB.Connect.streamPublish('', attachment, action_links, null, "Post this:", jscallback);
                    } else {
                    // permission granted, post without facebook dialog
                       FB.Connect.forceSessionRefresh(function() {
                       FB.Connect.streamPublish('', attachment, action_links, null, "Post this:", jscallback,true);
                    });
                }
            }, true, null);
        } else {
            // permission already granted, post suddenly
            // without facebook dialog
            FB.Connect.streamPublish('', attachment, action_links, null, "Post this:", jscallback,true);
            }
        });
    });
});
}

The function just hangs and nothing happens. I searched on this forum and found this post

function fb_publish() {
     FB.ui(
       {
         method: 'stream.publish',
         message: 'Message here.',
         attachment: {
           name: 'Nom ici.',
           caption: 'Caption here.',
           description: (
             'description here'
           ),
           href: 'url here'
         },
         action_links: [
           { text: 'Code', href: 'action url here' }
         ],
         user_prompt_message: 'Personal message here'
       },
       function(response) {
         if (response && response.post_id) {
           alert('Post was published.');
         } else {
           alert('Post was not published.');
         }
       }
     );  
  }

This one works, but it has two problems
1) Even though when the user logs in first time using graph API and they have granted extended permissions to publish to their wall, this method will everytime ask the user whether to allow or not - The previous one did not do that.
2) This method also allows user to add their comments - I dont want this either.

I want to seamlessly publish to the wall without again explicitly asking for the permission as they have already granted it before.

I am using PHP - any tips will be appreciated
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

汹涌人海 2024-09-15 02:17:15

我想这就是你要找的。

预先获取权限。

然后使用 Graph API 而不是 Javascript SDK 发布到流。
(这在发布时根本不会涉及用户,并且将在您的 php 代码中的服务器端发生)

I think this is what you're looking for.

Take the permissions upfront.
And
then publish to stream using Graph API rather than Javascript SDK.
(this will not involve the user at all while publishing, and will happen on server side in your php code)

过度放纵 2024-09-15 02:17:15

我无法找到使用 Javascript 的方法 - 所以我使用 php

try 
{
   $statusUpdate = $facebook->api('/me/feed', 'post', array('message'=> 'example status message', 'cb' => ''));
} 
catch (FacebookApiException $e) 
{

}


希望它可以帮助别人

I could not figure out a way to do it using Javascript - so I used php instead

try 
{
   $statusUpdate = $facebook->api('/me/feed', 'post', array('message'=> 'example status message', 'cb' => ''));
} 
catch (FacebookApiException $e) 
{

}


Hope it helps someone

锦上情书 2024-09-15 02:17:15

尝试将此代码发布在墙上

FB.ui(
            {
                method: 'feed',
                name: 'NAME',
                link: 'LINK OF THE WEBSITE OR PAGE',
                picture: 'IMAGE_URL IF YOU NEED IT',
                caption: 'Reference Documentation',
                description: "DESCRIPTION"
            },
            function(response) {
                if (response && response.post_id) {
                    alert('Post was published.');

                } else {
                    alert('Post was not published.');
                }
            }
        );

此代码适用于我的应用程序。希望它也能解决您的问题。

try this code to post on wall

FB.ui(
            {
                method: 'feed',
                name: 'NAME',
                link: 'LINK OF THE WEBSITE OR PAGE',
                picture: 'IMAGE_URL IF YOU NEED IT',
                caption: 'Reference Documentation',
                description: "DESCRIPTION"
            },
            function(response) {
                if (response && response.post_id) {
                    alert('Post was published.');

                } else {
                    alert('Post was not published.');
                }
            }
        );

This code works on my app. hope it'll solve your problem too .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文