代码之家  ›  专栏  ›  技术社区  ›  Gublooo

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

  •  0
  • Gublooo  · 技术社区  · 14 年前

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

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

    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) 即使当用户第一次使用graph API登录并且授予了发布到其墙的扩展权限时,此方法每次都会询问用户是否允许-前一个方法没有这样做。 2) 这个方法还允许用户添加他们的评论-我也不想这样。

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

    3 回复  |  直到 7 年前
        1
  •  0
  •   cdpnet    14 年前

    我想这就是你要找的。

    预先获取权限。 然后使用Graph API而不是Javascript SDK发布到流。 (这在发布时根本不涉及用户,而是在php代码的服务器端进行)

        2
  •  0
  •   Gublooo    14 年前

    我想不出一种使用Javascript的方法,所以我改用php

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

    希望它能帮助别人

        3
  •  0
  •   Raquibul Islam    13 年前

    试着把这个代码贴在墙上

    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.');
                    }
                }
            );