MZH
MZH

Reputation: 1514

POST Facebook Notification using Graph API

I'm trying to post notification using facebook graph api post method but I'm getting

(#15) This method must be called with an app access_token.

However the access_token which I'm sending in querystring is app access token which is fetched using this method

$token_url = "https://graph.facebook.com/oauth/access_token?client_id=".FB_APP_ID."&client_secret=".FB_SECRET."&grant_type=client_credentials";

I 've seen few guys have implemented it but don't know why its not working for me, someone pls tell me where I'm wrong in it.

Thanks

EDIT

I got it working, here is the change

This line of code will never work, because the internal access_token will override the app access_token which we are trying to pass in query string.

$this->facebook->api("/".$to_userId."/notifications?access_token=$app_token_url&template=message",'POST');

So Use this code

    $data = array(
    'href'=> 'https://apps.facebook.com/MY_APP/',
    'access_token'=> $app_token,
    'template'=> 'test'
    );
    try {

    $this->facebook->api("/".$to_userId."/notifications",'POST',$data);
    } catch (FacebookApiException $e) {

    }

Upvotes: 0

Views: 3040

Answers (1)

Igy
Igy

Reputation: 43816

Is your app accidentally configured as a 'native/desktop' app in the app settings? if so, change it back to 'web'

Upvotes: 1

Related Questions