Skip to content

Instantly share code, notes, and snippets.

@kosso
Last active December 13, 2015 20:19
Show Gist options
  • Save kosso/4969168 to your computer and use it in GitHub Desktop.
Save kosso/4969168 to your computer and use it in GitHub Desktop.
PHP to upload an avatar image to App.net
<?
// App.net Avatar uploader
// @Kosso
$access_token = 'AQAAAAAAAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$file_path = 'some_hilarious.gif';
$mime_type = 'image/gif';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://alpha-api.app.net/stream/0/users/me/avatar");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$access_token));
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
$post = array(
"avatar"=>"@".$file_path.";type=".$mime_type.";"
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = json_decode(curl_exec($ch));
echo 'Result:<br /><pre>';
print_r($response);
echo '</pre>';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment