FacebookFanpageConnect

The Facebook Fanpage Import FacebookFanpageConnect class.

Defined (1)

The class is defined in the following location(s).

/components/import/facebook.php  
  1. class FacebookFanpageConnect{ 
  2. var $access_token; 
  3. var $page_id; 
  4.  
  5. /** 
  6. * Initializes the Component. 
  7. * @since 1.0.0 
  8. */ 
  9. function __construct( $page_id, $access_token = '' ) { 
  10. $this->access_token = '1412978082344911|a7f5722a2b02f24aad0cda61ae5c4fe9'; 
  11.  
  12. if( '' != $access_token ) 
  13. $this->access_token = $access_token; 
  14.  
  15. $this->page_id = $page_id; 
  16.  
  17. function create_access_token( $app_id, $app_secret ) { 
  18. $access_token = $app_id . '|' . $app_secret; 
  19. return $data; 
  20.  
  21. function get_page() { 
  22. $url = 'https://graph.facebook.com/v2.1/'; 
  23. $url.= $this->page_id; 
  24. $url.= '?access_token=' . $this->access_token; 
  25.  
  26. $data = $this->fetch_data( $url ); 
  27. $data = json_decode( $data ); 
  28.  
  29. return $data; 
  30.  
  31. function get_posts( $limit = 10 ) { 
  32. $url = 'https://graph.facebook.com/v2.1/'; 
  33. $url.= $this->page_id . '/'; 
  34. $url.= 'posts/'; 
  35. $url.= '?access_token=' . $this->access_token; 
  36. $url.= '&limit=' . $limit; 
  37.  
  38. $data = $this->fetch_data( $url ); 
  39.  
  40. $data = json_decode( $data ); 
  41.  
  42. return $data->data; 
  43.  
  44. function get_post_picture( $post_id ) { 
  45. $url = 'https://graph.facebook.com/v2.1/'; 
  46. $url.= $post_id; 
  47. $url.= '?access_token=' . $this->access_token; 
  48. $url.= '&fields=full_picture'; 
  49.  
  50. $data = $this->fetch_data( $url ); 
  51. $data = json_decode( $data ); 
  52.  
  53. return $data; 
  54.  
  55. function get_photo_by_object( $object_id ) { 
  56. $url = 'https://graph.facebook.com/v2.1/'; 
  57. $url.= $object_id; 
  58. $url.= '?access_token=' . $this->access_token; 
  59.  
  60. $data = $this->fetch_data( $url ); 
  61. $data = json_decode( $data ); 
  62.  
  63. $data = $data->images[ 0 ]->source; 
  64.  
  65. return $data; 
  66.  
  67. private function fetch_data( $url ) { 
  68. if( is_callable( 'curl_init' ) ): 
  69. $con = curl_init(); 
  70.  
  71. curl_setopt( $con, CURLOPT_URL, $url ); 
  72. curl_setopt( $con, CURLOPT_RETURNTRANSFER, 1 ); 
  73. curl_setopt( $con, CURLOPT_TIMEOUT, 20 ); 
  74. curl_setopt( $con, CURLOPT_SSL_VERIFYPEER, false ); 
  75.  
  76. $data = curl_exec( $con ); 
  77.  
  78. curl_close( $con ); 
  79.  
  80. elseif ( ini_get( 'allow_url_fopen' ) === TRUE || ini_get( 'allow_url_fopen' ) == 1 ): 
  81. $data = @file_get_contents($url); 
  82.  
  83. else: 
  84. if( !class_exists( 'WP_Http' ) ) include_once( ABSPATH . WPINC. '/class-http.php' ); 
  85. $request = new WP_Http; 
  86. $result = $request->request($url); 
  87. $data = $result['body']; 
  88. endif; 
  89.  
  90. return $data; 
  91.