Created
October 29, 2012 15:27
-
-
Save codearachnid/3974181 to your computer and use it in GitHub Desktop.
Tri.be Events Facebook Importer hotfix for getting facebook photos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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