Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

new PHP 5 SDK samples for YAP

  • Loading branch information...
commit fdee58cf96c805a4bcead8758541e56f2b6bf5a1 1 parent ae2906b
@jcleblanc jcleblanc authored
View
12 php5_sdk/basic_3_legged.php
@@ -0,0 +1,12 @@
+<?php
+require_once 'lib/OAuth/OAuth.php';
+require_once 'lib/Yahoo/YahooOAuthApplication.class.php';
+
+//define application key constants
+define("CONSUMER_KEY", "KEY HERE");
+define("SHARED_SECRET", "KEY HERE");
+define("APP_ID", "APPLICATION ID HERE");
+
+//initiate a 3-legged OAuth request
+$oauthapp = YahooOAuthApplication::fromYAP(CONSUMER_KEY, SHARED_SECRET, APP_ID);
+?>
View
18 php5_sdk/notifications_set.php
@@ -0,0 +1,18 @@
+<?php
+require_once 'lib/OAuth/OAuth.php';
+require_once 'lib/Yahoo/YahooOAuthApplication.class.php';
+
+//define application key constants
+define("CONSUMER_KEY", "KEY HERE");
+define("SHARED_SECRET", "KEY HERE");
+define("APP_ID", "APPLICATION ID HERE");
+
+//create 3-legged OAuth request
+$oauthapp = YahooOAuthApplication::fromYAP(CONSUMER_KEY, SHARED_SECRET, APP_ID);
+
+//make request to YQL for post new update (viewable on pulse.yahoo.com)
+$query = "insert into social.notifications (guid, title, appmsg, category, image.size, image.width, image.height, image.imageUrl, expiry, choice1.label, choice1.urltemplate) values (me, 'Welcome to my application', 'Here\'s a gift. Can you send one back to me?', 'gift', '40x40', 40, 40, 'http://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Commons-logo.svg/30px-Commons-logo.svg.png', 1443603778, 'Send Gift', 'http://apps.yahoo.com/-APPID/?page=index.php&request_button_href_success=1&request_id={id}')";
+$response = $oauthapp->yql($query, array(), 'PUT');
+
+echo "Notification Response: {$response->query->results->notification}";
+?>
View
22 php5_sdk/profile_get.php
@@ -0,0 +1,22 @@
+<?php
+require_once 'lib/OAuth/OAuth.php';
+require_once 'lib/Yahoo/YahooOAuthApplication.class.php';
+
+//define application key constants
+define("CONSUMER_KEY", "KEY HERE");
+define("SHARED_SECRET", "KEY HERE");
+define("APP_ID", "APPID HERE");
+
+//create 3-legged OAuth request
+$oauthapp = YahooOAuthApplication::fromYAP(CONSUMER_KEY, SHARED_SECRET, APP_ID);
+
+//make request to YQL to get profile of the user from pulse.yahoo.com
+$response = $oauthapp->getProfile();
+
+//dump all profile elements
+foreach ($response->profile as $key => $value){
+ echo "$key: ";
+ print_r($value);
+ echo '<br />';
+}
+?>
View
32 php5_sdk/relationships_get.php
@@ -0,0 +1,32 @@
+<?php
+require_once 'lib/OAuth/OAuth.php';
+require_once 'lib/Yahoo/YahooOAuthApplication.class.php';
+
+//define application key constants
+define("CONSUMER_KEY", "KEY HERE");
+define("SHARED_SECRET", "KEY HERE");
+define("APP_ID", "APPID HERE");
+
+//create 3-legged OAuth request
+$oauthapp = YahooOAuthApplication::fromYAP(CONSUMER_KEY, SHARED_SECRET, APP_ID);
+
+//make request to YQL to get relationships for current user
+//will return guid, uri and categories for each
+$response = $oauthapp->getRelationships();
+
+//for each relationship, obtain the profile and display
+foreach ($response->relationsWithCategories->relations->relation as $relation){
+ //get guid of the current relation & then profile using the guid
+ $guid = $relation->guid;
+ $profile = $oauthapp->getProfile($guid);
+
+ echo "<h1>Profile: {$profile->profile->nickname}</h1>";
+
+ //for each profile, display all profile elements
+ foreach ($profile->profile as $key => $value){
+ echo "$key: ";
+ print_r($value);
+ echo '<br />';
+ }
+}
+?>
View
23 php5_sdk/updates_get.php
@@ -0,0 +1,23 @@
+<?php
+require_once 'lib/OAuth/OAuth.php';
+require_once 'lib/Yahoo/YahooOAuthApplication.class.php';
+
+//define application key constants
+define("CONSUMER_KEY", "KEY HERE");
+define("SHARED_SECRET", "KEY HERE");
+define("APP_ID", "APPLICATION ID HERE");
+
+//create 3-legged OAuth request
+$oauthapp = YahooOAuthApplication::fromYAP(CONSUMER_KEY, SHARED_SECRET, APP_ID);
+
+//make request to YQL for current user updates and capture update response object
+$response = $oauthapp->yql('SELECT loc_longForm, link, description FROM social.updates(100) WHERE guid=me', array('diagnostics' => 'false', 'debug' => 'false'), "GET");
+$updates = $response->query->results->update;
+
+//for each update, display the title, description and link
+for ($i = 0; $i < count($updates) - 1; $i++){
+ $html = "<a href='{$updates[$i]->link}'>{$updates[$i]->loc_longForm}</a>
+ <br />{$updates[$i]->description}<br /><br />";
+ echo $html;
+}
+?>
View
34 php5_sdk/updates_set.php
@@ -0,0 +1,34 @@
+<?php
+require_once 'lib/OAuth/OAuth.php';
+require_once 'lib/Yahoo/YahooOAuthApplication.class.php';
+
+//define application key constants
+define("CONSUMER_KEY", "KEY HERE");
+define("SHARED_SECRET", "KEY HERE");
+define("APP_ID", "APPLICATION ID HERE");
+
+//create 3-legged OAuth request
+$oauthapp = YahooOAuthApplication::fromYAP(CONSUMER_KEY, SHARED_SECRET, APP_ID);
+
+//make request to YQL for post new update (viewable on pulse.yahoo.com)
+//$query = "INSERT INTO social.updates (guid, title, description, link, imgURL, imgWidth, imgHeight) VALUES (me, '$title', '$description', '$link', '$img_url', '$img_width', '$img_height')";
+//$response = $oauthapp->yql($query, array(), YahooCurl::PUT);
+
+$params = array(
+ 'title' => 'Posting an update from YAP',
+ 'description' => 'This is an automatic update posted through YQL using the PHP 5 SDK',
+ 'link' => 'http://developer.yahoo.com/yap',
+ 'imgURL' => 'http://l.yimg.com/a/i/ydn/sst/44/yql.gif',
+ 'imgHeight' => '44',
+ 'imgWidth' => '44'
+);
+
+$response = $oauthapp->insertUpdate(null, $params);
+
+//check update status. If success, update succeeded
+if ($response){
+ echo 'update posted successfully';
+} else {
+ echo 'update post failed';
+}
+?>
View
15 php5_sdk/yql_get.php
@@ -0,0 +1,15 @@
+<?php
+require_once 'lib/OAuth/OAuth.php';
+require_once 'lib/Yahoo/YahooOAuthApplication.class.php';
+
+//define application key constants
+define("CONSUMER_KEY", "KEY HERE");
+define("SHARED_SECRET", "KEY HERE");
+define("APP_ID", "APPLICATION ID HERE");
+
+//initiate a 3-legged OAuth request
+$oauthapp = YahooOAuthApplication::fromYAP(CONSUMER_KEY, SHARED_SECRET, APP_ID);
+
+//make request to YQL (insert your YQL query below)
+$response = $oauthapp->yql('YQL QUERY HERE', array('diagnostics' => 'true', 'debug' => 'true'), "GET");
+?>

0 comments on commit fdee58c

Please sign in to comment.
Something went wrong with that request. Please try again.