php - How to get Facebook Page info using Guzzle -


i'm sure i'm missing but, currently, don't understand what.

i'm playing guzzle, , i'm trying page info:

<?php  /**  * example of usage of apiconnect information  * facebook page through graph api.  */  require('../vendor/autoload.php');  /** set here page */ $page = 'samplepage';  $remoteurl = 'https://graph.facebook.com/' . $page;  $client = new guzzlehttp\client(); $res = $client->get($remoteurl); echo $res->getstatuscode(); // "200" echo $res->getheader('content-type'); // 'application/json; charset=utf8' echo $res->getbody(); // {"type":"user"...' 

this code guzzle documentation shows.

now, i'm expecting calling code, returns objects contains, in 1 of properties, following json response, 1 receive if call url directly in browser:

{    "error": {       "message": "an access token required request resource.",       "type": "oauthexception",       "code": 104    } } 

why, instead, if use guzzle methods response values see null? missing?

ok, solved this.

the first problem used old version of guzzle.

in composer.json had this:

## wrong ## "require": {     "guzzlehttp/guzzle": "*@stable" }, 

but in way downloaded guzzle 3, old version.

to download new version (the 6), changed line in way:

## correct ## "require": {     "guzzlehttp/guzzle": "~6" }, 

so, have guzzle 6.

also code has changed. correct version:

<?php  /**  * example of usage of apiconnect information  * facebook page through graph api.  */  require('../vendor/autoload.php');  use guzzlehttp\client; use guzzlehttp\exception\requestexception;  $url = 'https://graph.facebook.com/samplepage'; // set url $api_end_point = ''; $end_point = '';  $client = new client(     ['base_uri' => $url]     );  $path = $api_end_point . $end_point; echo $path;  try {     $res = $client->get($path); } catch (requestexception $e) {     $res = $e->getrequest();      if ($e->hasresponse())     {         $res = $e->getresponse();     } }  echo $res->getstatuscode(); // "400" print_r($res->getheader('content-type')); // array ( [0] => text/javascript; charset=utf-8 ) echo $res->getbody(); // {"error":{"message":"an access token required request resource.","type":"oauthexception","code":104}} 

now guzzle returns response. 400 status code because need authentication, question :)


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -