Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codearachnid/3974181 to your computer and use it in GitHub Desktop.
Save codearachnid/3974181 to your computer and use it in GitHub Desktop.
Tri.be Events Facebook Importer hotfix for getting facebook photos
<?php
// REPLACE YOUR CURRENT FUNCTION WITH THE FOLLOWING `get_facebook_photo` (line 268)
/**
* retrieve a facebook event photo url (after redirect) along with photo data
* example: https://graph.facebook.com/331218348435/?fields=picture&type=large
*
* @param string $object_id the object to retrieve
* @param string $size the size of the photo to retrieve (small, normal, large)
* @return array the image url
*/
function get_facebook_photo( $object_id, $size = 'large') {
// $api_url = $this->build_url_with_access_token( $object_id . '/picture', array('type' => $size) );
$api_url = $this->build_url_with_access_token( $object_id . '/', array( 'fields' => 'picture', 'type' => $size, 'return_ssl_resources' => 1 ) );
$get = wp_remote_get( $api_url );
$body = json_decode( $get['body'] );
// hardcoding the size for now since Facebook isn't returning what we request
$new_path = str_replace("_q.", "_n.", $body->picture->data->url);
$get_photo = wp_remote_get( $new_path );
// setup return object
$photo['url'] = $new_path;
$photo['source'] = $get_photo['body'];
return $photo;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment