Created
November 21, 2012 11:47
-
-
Save codearachnid/4124500 to your computer and use it in GitHub Desktop.
Retrieve a facebook event photo url
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
/** | |
* 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 apply_filters( 'tribe_events_importer_get_facebook_photo', $photo ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment