从apprequest facebook api请求数据

【从apprequest facebook api请求数据】宁可枝头抱香死,何曾吹落北风中。这篇文章主要讲述从apprequest facebook api请求数据相关的知识,希望能为你提供帮助。
Rescatamos los datos que pasamos por apprequest .

  1. //C?3digo javascript
  2. function sendRequest( user) {
  3. FB.ui( {
  4. method: 'apprequests',
  5. title: 'Concurso Hipoglos',
  6. message: 'Invita a tus amigos a subir a tu bus de hipoglos y ganar fantasticos premios.',
  7. data: '{" item_id" :'+user+'," item_type" :" plant" }'
  8. } ,
  9. function ( response) {
  10. if ( response & & response.request_ids) {
  11.  
  12. alert( 'Tus invitaciones han sido enviadas, tus amigos recibiran una notificacion para subir a tu bus. Recueda que estas participando cuando tengas 20 pasajeros en el bus.') ;
  13.  
  14. } else {
  15.  
  16. //Do something if they don't send it.
  17.  
  18. }
  19. } ) ;
  20. }
  21.  
  22.  
  23.  
  24. //Rescatando datos desde php
  25. if( isset( $_REQUEST[ 'request_ids'] ) ) {
  26.  
  27. // Requesting an application token
  28. $token_url =" https://graph.facebook.com/oauth/access_token?" .
  29. " client_id=" . $fbconfig[ 'appid' ] .
  30. " & client_secret=" . $fbconfig[ 'secret'] .
  31. " & grant_type=client_credentials" ;
  32. $app_token = file_get_contents( $token_url) ;
  33.  
  34. // You may have more than one request, so it's better to loop
  35. $requests = explode( ',',$_REQUEST[ 'request_ids'] ) ;
  36. foreach( $requests as $request_id) {
  37. // Get the request details using Graph API
  38. $request_content = json_decode( file_get_contents( " https://graph.facebook.com/$request_id?$app_token" ) , TRUE) ;
  39.  
  40. // An example of how to get info from the previous call
  41. $from_id = $request_content[ 'from'] [ 'id'] ;
  42. $to_id = $request_content[ 'to'] [ 'id'] ;
  43.  
  44. // An easier way to extract info from the data field
  45. extract( json_decode( $request_content[ 'data'] , TRUE) ) ;
  46. // Now that we got the $item_id and the $item_type, process them
  47. // Or if the recevier is not yet a member, encourage him to claims his item (install your application)!
  48. $redirect_from_app = $fbconfig[ 'appUrl'] . " & app_data=https://www.songbingjia.com/android/" . $item_id;
  49. $loginUrl = $facebook-> getLoginUrl( array( 'scope' => 'email,publish_stream', 'redirect_uri' => $redirect_from_app) ) ;
  50. // When all is done, delete the requests because Facebook will not do it for you!
  51. //$deleted = file_get_contents(" https://graph.facebook.com/$request_id?$app_token& method=delete" ); // Should return true on success
  52. }
  53. }


    推荐阅读