Skip to content
Newer
Older
100644 46 lines (34 sloc) 1.36 KB
2a3fd51 sample code for fetching yahoo profile data asynchronously using stor…
erik authored
1 <?php
2
b3da6db added link to license in all code files
erik authored
3 /*
4 * Copyright: (c) 2009, Yahoo! Inc. All rights reserved.
5 * License: code licensed under the BSD License. See [license.markdown](http://github.com/ydn/async_profile_fetch/blob/master/license.markdown)
6 */
7
2a3fd51 sample code for fetching yahoo profile data asynchronously using stor…
erik authored
8 require_once("../../yosdk/yahoo-yos-social-php-1fe1b43/lib/Yahoo.inc");
9 require_once("CustomSessionStore.php");
10
11 //define constants
12 require 'config.php';
13
14 function respond ($response)
15 {
16 header('content-type: application/json');
17 echo json_encode($response);
18 die;
19 }
20
21 if (!$_GET['guid']) {
22 respond(array('error' => 'guid is required'));
23 }
24
25 $store = new CustomSessionStore($_GET['guid']);
26 $access_token = $store->fetchAccessToken();
27
28 $consumer = (object) array(
29 'key' => KEY,
30 'secret' => SECRET
31 );
32
33 //token will expire in < 30 sec, so try to refresh
34 if (($access_token->tokenExpires >= 0) && ($access_token->tokenExpires - time()) < 30) {
35 YahooSession::accessTokenExpired($access_token, $consumer, APPID, $store);
36 }
37
38 //use yahoosession for convenient yql oauth requests
39 $session = new YahooSession($consumer, $access_token, APPID);
40
41 //more info: http://developer.yahoo.com/yql/console/?q=select%20image.imageUrl%2C%20familyName%2C%20givenName%20from%20social.profile%20where%20guid%3Dme
42 $yql = sprintf('select image.imageUrl, familyName, givenName from social.profile where guid="%s"', $_GET['guid']);
43
44 respond(array('success' => $session->query($yql)));
45
46 ?>
Something went wrong with that request. Please try again.