简体   繁体   中英

Using Facebook's PHP SDK, getGraphObject->asArray() returning an object?

I'm calling objects from Facebook's new PHP SDK, and i am crating the objects as below, however, for 2 seperate reqeusts that I'm calling identically, they are not coming back the same. The first request comes back as an Array (as hoped). The second, comes back as an object, and for the life of me I don't understand why.

$fb_session = new FacebookSession( $fb_session->getToken() );

// graph api request for user data
$fb_user_array = (new FacebookRequest( $fb_session, 'GET', '/me' ))->execute()->getGraphObject()->asArray();

echo "FB USER >> A" . $fb_user_array['id'];     // WORKS
echo "FB USER >> B" . $fb_user_array->id;       // FAILS

$picture_array = (new FacebookRequest( $fb_session, 'GET', '/me/picture?type=large&type=square&redirect=false' ))->execute()->getGraphObject()->asArray();

echo "FB PIC >> A " . $picture_array['url'];    // FAILS!!
echo "FB PIC >> A " . $picture_array->url;      // WORKS??

This was a bug in the PHP SDK that has since been fixed . Just download the latest version of 4.0 and you shouldn't have this issue anymore. :)

This is working now. Actually you help me found the correct syntax of the GET, since the fb developers page gives an example that produce errors... (how original huh??). I understand that bugs can exists in any new API (fb or whatever) but what is very frustrated are in the very bad API examples in the fb developers page as well as the the errors too. Many times I just wondering if they ever test what they publish. I don't know the dev team behind this, but if they are the well payed fb developers it is at least ridiculous.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM