0

PHP SDK for Yahoo! Social Platform (YSP)

The PHP SDK makes using Y!OS Web Services a lot easier by automating the OAuth web authentication and REST calls to the Social Directory APIs.

Download the PHP SDK and take a look at the PHP SDK Guide for YSP.

Here's a code tease that uses six lines to get a Yahoo! user's profile. Good luck!

CODE
  // Include the SDK and define constants to store Consumer Key/Secret
require_once("YourDirectory/yosdk/libYahoo.inc");
define('CONSUMER_KEY',"place_your_key_here");
define('CONSUMER_SECRET',"place_your_secret_here");

// Perform OAuth Web Authentication and return a session object
$yahoo_session = YahooSession::requireSession(CONSUMER_KEY, CONSUMER_SECRET);

// The YahooSession object $yahoo_session uses the method getSessionedUser to get a YahooUser object $yahoo_user
$yahoo_user = $yahoo_session->getSessionedUser();

// With the YahooUser object, the user extended profile is obtained with the method loadProfile.
$user_profile = $yahoo_user->loadProfile();

by
  • Me
  • Sep 30, 2008
5 Replies
  • so, i have this basic stuff working, and say i get a contact back with it's uri to the socialapi.

    how do i call that via php to get the info for this contact? i keep getting invalid credentials when i try to access any socialapi uri's.

    ie, http://social.yahooapis.com/v1/user/{guid is here}/contact/2
    0
  • Hi rooster,

    One of the ways you can collect user data on a specific contact is by using the PHP SDK methods themselves. If you're not using the SDK and are calling the raw URL's the collect user data you're going to have to set up your own 3-legged OAuth / Yahoo! user session to collect the data...much easier to use the SDK found here: http://developer.yahoo.com/social/sdk/. There is information at that link on how to set up the SDK and use its functionality.

    The method within the SDK that you can use to get data for a specific user is "getUser($guid)". This method accepts one parameter, the guid of the user that you are trying to collect data for. I just ran a test against my contact id and was able to return a Yahoo user object containing my data. You could call this method using something like:

    CODE
    $session = YahooSession::requireSession($consumerKey, $consumerKeySecret);
    $userData = $session->getUser('GUID');


    $userData should now contain the data you need. Please let us know if you run into any issues along the way.

    Jonathan LeBlanc
    Senior Software Engineer
    Yahoo! Developer Network

    QUOTE (rooster @ Nov 6 2008, 12:19 AM) <{POST_SNAPBACK}>
    so, i have this basic stuff working, and say i get a contact back with it's uri to the socialapi.

    how do i call that via php to get the info for this contact? i keep getting invalid credentials when i try to access any socialapi uri's.

    ie, http://social.yahooapis.com/v1/user/{guid is here}/contact/2
    0
  • Actually sorry rooster, that getData will probably not give you the data you need. What you'll want to look at are the getContacts and getConnections methods. These will collect your connections (two way authorized - which will return more user data) or contacts (one way authorized - which will return very basic data). From that data, you can use YQL queries to collect user information by guid - see http://developer.yahoo.com/yql/docs/#Socia...e_SELECT_what_F for details on that.

    So, you're connection / contact calls will look like:

    CODE
    // Include the YOS library.  
    require("Yahoo.inc");

    // Get a session first. If the viewer isn't sessioned yet, this call
    // will redirect them to log in and authorize your application to
    $session = YahooSession::requireSession($consumerKey, $consumerKeySecret, $applicationId);

    // Get the currently sessioned user. That means the user who is
    // currently viewing this page.
    $user = $session->getSessionedUser();

    // Access the connection list for the current user.
    $start = 0; $count = 100; $total = 0;
    $connections = $user->getConnections($start, $count, $total);

    // Access the contact list for the current user
    $contactList = $user->getContacts($start, $count);


    - Jonathan LeBlanc
    0
  • got it working. thanks!

    btw, are there any social api's to "message" or use the notification system? i can use it fine in <yaml>, and YAP apps, but using OAuth, and the contacts/etc api's, is it possible to message a connection or even send an email? the connection object doesn't have a handle to the email or i'd just email as a fallback.



    QUOTE (jon.leblanc@rogers.com @ Nov 6 2008, 09:37 AM) <{POST_SNAPBACK}>
    Hi rooster,

    One of the ways you can collect user data on a specific contact is by using the PHP SDK methods themselves. If you're not using the SDK and are calling the raw URL's the collect user data you're going to have to set up your own 3-legged OAuth / Yahoo! user session to collect the data...much easier to use the SDK found here: http://developer.yahoo.com/social/sdk/. There is information at that link on how to set up the SDK and use its functionality.

    The method within the SDK that you can use to get data for a specific user is "getUser($guid)". This method accepts one parameter, the guid of the user that you are trying to collect data for. I just ran a test against my contact id and was able to return a Yahoo user object containing my data. You could call this method using something like:

    CODE
    $session = YahooSession::requireSession($consumerKey, $consumerKeySecret);
    $userData = $session->getUser('GUID');


    $userData should now contain the data you need. Please let us know if you run into any issues along the way.

    Jonathan LeBlanc
    Senior Software Engineer
    Yahoo! Developer Network
    0
  • Hey rooster, I just pushed out a reply for this concern in your other topic: http://developer.yahoo.net/forum/index.php...0&#entry805

    - Jon

    QUOTE (rooster @ Nov 6 2008, 10:12 AM) <{POST_SNAPBACK}>
    got it working. thanks!

    btw, are there any social api's to "message" or use the notification system? i can use it fine in <yaml>, and YAP apps, but using OAuth, and the contacts/etc api's, is it possible to message a connection or even send an email? the connection object doesn't have a handle to the email or i'd just email as a fallback.
    0

Recent Posts

in Social Directory API