Ido Sorozon
Ido Sorozon

Reputation: 279

Using Facebook Graph API to post on user wall

I want to use Graph API to post from user1 on user2 wall.

I've got an access_token for user1 with publish_actions permission, like It says in the Graph API reference. and called

access_token='<token-for-user1>'
user2='<id-of-user2>'
curl -s \
    -XPOST \
    -d "access_token=$access_token" \
    -d "message=$message" \
    "https://graph.facebook.com/v2.12/${user2}/feed"

but all I get is:

{
    "error": {
        "message": "Unsupported post request. Object with ID '$user2' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https:\/\/developers.facebook.com\/docs\/graph-api",
        "type": "GraphMethodException",
        "code": 100,
        "error_subcode": 33,
        "fbtrace_id": "***********"
    }
}

What am I doing wrong and how can I fix it?

I thank you in advance,

Ido


Login script:

app_access_token="$app_id|$client_token"

# Give user_code to user1, and save code as $code
curl -s \
    -XPOST \
    -d "access_token=$app_access_token" \
    -d 'scope=publish_actions' \
    -d 'redirect_uri=https://www.facebook.com/connect/login_success.html' \
    'https://graph.facebook.com/v2.12/device/login'

# user1 goes to https://www.facebook.com/device
...

# Save access_token in $access_token and use in the code above
curl -s \
    -XPOST \
    -d "access_token=$app_access_token" \
    -d "code=$code" \
    'https://graph.facebook.com/v2.12/device/login_status'

Thing I've added to the app:

Upvotes: 2

Views: 2461

Answers (2)

Sammy7
Sammy7

Reputation: 372

As of April 24,2018, the pubish_actions permission has been removed. Please see the Breaking Changes Changelog for more details. To provide a way for your app users to share content to Facebook, we encourage you to use our Sharing products instead.

See Documentation: https://developers.facebook.com/docs/facebook-login/android/permissions#permissions-publish

Upvotes: 2

andyrandy
andyrandy

Reputation: 73984

There is no way to post on the wall of another user. You can only post on the wall of the current user, with his own Access Token and the publish_actions permission.

Sharer.php offers the possibility to select a friend, that´s the only way: https://www.facebook.com/sharer/sharer.php?u=[encoded-url]

You can also use the Share Dialog, it offers the option to select a friend too: https://developers.facebook.com/docs/sharing/reference/share-dialog

Upvotes: 2

Related Questions