Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
publish an update w/ image to Yahoo! using the PHP SDK
This script creates an oauth access token for you, and then
allows you to use that token to publish an update (that
includes a thumbnail picture) w/ the Yahoo! Updates API
* A server with PHP 5
* A valid domain for that server
* An OAuth app from the Yahoo! Dev. Network:
* The Yahoo! PHP SDK:
1. Put this script in a file on your server
2. Edit the include path for the Yahoo! PHP SDK
3. Edit the definitions of your app's key, secret, and id
4. Browse to the url of this script, log in to Yahoo!,
click the button, and then browse to to
see the new update
//define constants
define('KEY', '');
define('SECRET', '');
define('APPID', '');
$session = YahooSession::requireSession(KEY, SECRET, APPID);
if ('true' == $_GET['post']) {
//ref: YahooUser::insertUpdate() in
$source = 'APP.'.APPID;
$suid = 'ugc';
$request_url = sprintf(
$update_body = array(
'updates' => array(
"class" => "app",
"collectionType" => "guid",
"collectionID" => $session->guid,
"type" => "appActivity",
//cast to string to avoid "...missing Required field: [pubDate..." error
"pubDate" => (string) time(),
"source" => $source,
"suid" => $suid,
"description" => 'The time is now '.date("g:i a"),
"title" => 'foo title',
"link" => '',
"imgURL" => "",
"imgWidth" => "240",
"imgHeight" => "150"
$update_body_json = json_encode($update_body);
//check output on
$response = $session->client->put($request_url, "application/json", $update_body_json);
header('content-type: text/javascript');
//response returned as json, so just pass it along for sanity checking
echo 'handleResponse('.$response['responseBody'].');';
} else {
<button id="button">click to post update</button>
var handleResponse = function (data) {
document.getElementById('button').innerHTML='posted :)';
if (console) {
handleClick = function (e) {
var script = document.createElement('script');
script.src = '?post=true';
document.getElementById('button').onclick = handleClick;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment