Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send Message from application to facebook user

Can I create an application that provides notification to facebook user when there is a change of user in my application?

I'm building an e-learning that is integrated with Facebook.

like image 942
Fendi Tri Cahyono Avatar asked Oct 09 '22 05:10

Fendi Tri Cahyono


1 Answers

You can not send users messages from your application. If this were possible we would see lots of applications sending spam to everyone. What you can do is send app requests to your users when you want to notify them of a change in your application.
You can read more about requests and app requests at this url :
https://developers.facebook.com/blog/post/464/
Scroll down to "PHP example of an app-generated request"...

<?php 

  $app_id = YOUR_APP_ID;
  $app_secret = YOUR_APP_SECRET;

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

  $app_access_token = file_get_contents($token_url);

  $user_id = THE_CURRENT_USER_ID;

  $apprequest_url ="https://graph.facebook.com/" .
    $user_id .
    "/apprequests?message=’INSERT_UT8_STRING_MSG’" . 
    "&data=’INSERT_STRING_DATA’&"  .   
    $app_access_token . “&method=post”;

  $result = file_get_contents($apprequest_url);
  echo(“Request id number: ”, $result);
?>
like image 150
Lix Avatar answered Oct 13 '22 12:10

Lix