Skip to content
Browse files

Updating PHP client to support the POST /v1/user

Adding methods for posting and retrieving high scores
  • Loading branch information...
1 parent ac55a9b commit 4de80dcc510435d93fe6f8c7442523b4bcd117b9 Joseph Dayo committed Jan 31, 2012
Showing with 79 additions and 7 deletions.
  1. +52 −4 lib/FriendsterAPI.php
  2. +27 −3 test-api.php
View
56 lib/FriendsterAPI.php
@@ -1,7 +1,7 @@
<?php
/*
* FriendsterAPI PHP5 client
- * Copyright Friendster, Inc. 2002-2008
+ * Copyright Friendster, Inc. 2002-2012
*
*/
@@ -36,8 +36,9 @@ class FriendsterAPI {
const API_SHOUTOUT = 'shoutout';
const API_NOTIFICATION = 'notification';
const API_APPFRIENDS = 'application/friends';
- const API_WALLET = 'wallet';
+ const API_WALLET = 'wallet';
const API_WALLETSANDBOX = 'wallet-sandbox';
+ const API_SCORE = 'score';
private $isSandbox;
@@ -82,16 +83,63 @@ public function token() {
return $response[self::PARAM_AUTH_TOKEN];
}
- public function users($uids, $params = null, $response_type = FriendsterAPIResponseType::SARRAY,$callback = null) {
+ /** Get user info */
+ public function users($uids = null, $params = null, $response_type = FriendsterAPIResponseType::SARRAY,$callback = null) {
if ($params!=null && $callback!=null) {
- $params = array_merge(params,array('callback'=>$callback));
+ $params = array_merge($params,array('callback'=>$callback));
} else {
$params = array('callback'=>$callback);
}
return $this->doRequest(self::API_USERS, $uids, $params, Request::GET, $response_type);
}
+
+ /** Get user info using http POST, use this when retrieving a very large set of users */
+ public function users_p($uids = null, $params = null, $response_type = FriendsterAPIResponseType::SARRAY, $callback = null) {
+
+ if ($params!=null && $callback!=null) {
+ $params = array_merge(params,array('callback'=>$callback));
+ } else {
+ $params = array('callback'=>$callback);
+ }
+ if ($uids!=null) {
+
+ if (is_array($uids)) {
+ $uids = implode($uids,',');
+ }
+
+ $params = array_merge($params,array('uids'=>$uids));
+ }
+
+ return $this->doRequest(self::API_USERS, null, $params, Request::POST, $response_type);
+ }
+
+ //Post an avatars' score for your games' leaderboard
+ public function post_score($uid, $score, $params = null, $response_type = FriendsterAPIResponseType::SARRAY, $callback = null) {
+
+ $params = array('score'=>$score);
+
+ if ($params!=null && $callback!=null) {
+ $params = array_merge(params,array('callback'=>$callback));
+ } else {
+ $params = array('score'=>$score, 'callback'=>$callback);
+ }
+
+ return $this->doRequest(self::API_SCORE, $uid, $params, Request::POST, $response_type);
+ }
+
+ public function get_scores($params = null, $response_type = FriendsterAPIResponseType::SARRAY, $callback = null) {
+
+ if ($params!=null && $callback!=null) {
+ $params = array_merge(params,array('callback'=>$callback));
+ } else {
+ $params = array('callback'=>$callback);
+ }
+
+ return $this->doRequest(self::API_SCORE, null, $params, Request::GET, $response_type);
+ }
+
public function arefriends($uids, $response_type = FriendsterAPIResponseType::SARRAY,$callback = null) {
$params = array();
if ($callback!=null) {
View
30 test-api.php
@@ -1,12 +1,36 @@
<?php
+//simple PHP Demo for the v1 Friendster API
require_once "lib/FriendsterAPI.php";
+$API_KEY = '<API KEY>';
+$API_SECRET = '<API SECRET>';
+$SESSION_KEY = '<A SESSION KEY passed to your app via the iframe to your callback_url>';
+$fapi = new FriendsterAPI($API_KEY, $API_SECRET, $SESSION_KEY, 'http://www.friendster.com');
+//Get the current user
+$user_info = $fapi->users_p();
-$fapi = FriendsterAPI::from_friendster('4ee58f3f0ccdf62fe35a52d1b34cf0f6');
+print_r($user_info);
-print_r($fapi);
+$current_uid = $user_info[0]['uid'];
-?>
+//post high score for this user
+$fapi->post_score($current_uid, 100);
+
+//Get the high scores
+$results = $fapi->get_scores();
+
+print_r($results);
+
+
+//Get friends
+$friends = $fapi->friends();
+
+print_r($friends);
+
+$friends_list = $friends['friends'];
+
+//Display friend information
+$friend_user_info = $fapi->users_p($friends_list);

0 comments on commit 4de80dc

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