Search code examples
phpfacebookfacebook-graph-apifacebook-app-requests

Facebook Notification using graph api not working


I am trying to send app request notification to multiple friends using Graph api,,here is my code

   $apprequest_url="https://graph.facebook.com/" .
                       $user_id .
                       "/apprequests?message='My Message'" .
                       "&data='My Data'&"  .  
                       $app_access_token . "&method=post";

                     $result = file_get_contents($apprequest_url);

here $result is giving nothing. It shoud return success message.

I dont want to use

FB.ui({
method: 'apprequests',
    message: 'My Message',
    link: "http://topperlearning.com",
    picture: "http://mydomain.com/abc.jpg",
    to:userIds,
    title:'TopperLearning.com'
}, function(response) {
        console.log(response);            
    });`

because it gives firstly popup then user has to click on Send Request.That is why i am trying graph api.BUt not working.I am trapped just because of this


Solution

  • You should be able to use the Javascript version if you remember to activate frictionless requests.

    FB.init({
        appId  : 'YOUR_APP_ID',
        frictionlessRequests: true
      });
    

    In the PHP-version you seem to missing "access_token=" . $app_access_token
    You should probably urlencode your data as well.