简体   繁体   中英

Posting to facebook wall using graph api

I'm trying to post a text with image to facebook wall using graph api.

I'm using following code snippet for this.

 var body = {
      message : 'this is a test message',
      image : 'http://someurltoimage.png'
 };

 FB.api(
        "/me/feed",
        "POST",
        {
            "object": {
                "message": body.message,
                "picture": body.image
            }
        },
        function (response) {
          if (response && !response.error) {
              //process when success
          }
        }
    );

But I'm getting following error code.

 error: Object
 code: 100
 error_subcode: 1349125
 message: "Invalid parameter"
 type: "FacebookApiException"

There's no document for this error.

Any advise will be appreciated.

"I'm trying to post a text with image to facebook wall using graph api."

  • You are using /feed , to upload a photo you have to use /photos call
  • You are sending an invalid parameter object which contains your parameters, to Facebook, the API doesn't know that your parameter Object is an object (I know, too many object s here, in another way, you're sending an object within an object

To solve all this, replace me/feed with me/photos and the 3rd argument (your object) with the body

 var body = {
      message : 'this is a test message',
      url: 'http://someurltoimage.png'
 };

 FB.api("/me/photos",
        "POST",
        body,
        function (response) {
          if (response && !response.error) {
              //process when success
          }
        }
 );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM