开发者

Migrated to Facebook Graph API - application broken now - cannot post to wall

开发者 https://www.devze.com 2023-01-05 02:46 出处:网络
Yesterday I changed the application settings and enabled \"New Data Permissions\" and \"New SDKs\". After that the feature of postingmessage to the users wall stopped working. On my website, users lo

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 grant开发者_Go百科ed 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


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)


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


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 .

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号