Facebook/OS Integration
				
					Collapse
				
			
		
	Recommended Videos
				
					Collapse
				
			
		
	X
- 
	
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
 Re: Calling all programmers... (possible OS project)
 
 Question one:
 
 Here is some code i have
 
 Code:$user_info = $facebook->api_client->users_getinfo($user_array, $request_array); print_r($user_info); $firstName = $user_info["first_name"]; 
 here is the output I am seeing from the print function:
 
 Now, that last line of codeCode:Array ( [0] => Array ( [uid] => 7005303 [first_name] => Kevin [last_name] => Harwood ) ) 
 isnt giving me what I want. I can see I am gettign the data correctly from that print function, but how do I extract it correctly?Code:$firstName = $user_info["first_name"]; 
 
 
 EDIT: Figured it out. The function users_getinfo() returns an array of arrays... that was my problemComment
- 
	
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
 Re: Calling all programmers... (possible OS project)
 
 ok i'm calling it a night.
 
 I wanted to post what I have so far, just to let people look in.
 
 What I have written is a SIMPLE app that requires me to login to facebook. After that, I pull all of my friends id's from the database. I then get my own information (my name). I then pull ALL of my friends' names, and parse out the array accordingly, printing it to the screen.
 
 Here is the code.
 I have tried to add as many comments as possible. Keep in mind that the two facebook api classes I have left untouched, and can be found at the facebook developer site.
 
 File 1: appinclude.php
 
 This file is just simply some things are required for the facebook login. This is also where the login takes place.
 
 Code:require_once 'facebook.php'; $appapikey = '9457928fd3a2b15bb9d450ad7ea2a5f0'; //code from facebook app $appsecret = 'c68eecf53885b92e0af14250a407b45f'; // code from facebook app $facebook = new Facebook($appapikey, $appsecret); //creates new instance of Class Facebook $user = $facebook->require_login(); //forces user to login to facebook //[todo: change the following url to your callback url] $appcallbackurl = 'http://localhost:8888/Test/index.php'; 
 
 And here is my index.php
 
 Code:require_once 'appinclude.php'; // include in all files $friends = $facebook->api_client->friends_get(); //get all of my friend's ids $user_array = array($user); // create an array with just my id $request_array= array('first_name', 'last_name'); // create an array of the data i want to request $user_info = $facebook->api_client->users_getinfo($user_array, $request_array); //make the call to get the data $temp = $user_info[0]; // setting $temp to th array in spot 0, since it only contains one array $firstName = $temp['first_name']; //parsing my name $lastName = $temp['last_name']; // parsing my name echo "Your Name: $firstName $lastName<br>";//printing my name $i = 0; // set a counter $numOfElements = count($friends); //determine number of friends $friends_info = $facebook->api_client->users_getinfo($friends, $request_array);// get friends info while ($i<$numOfElements) //loop through all friends { $temp_array = $friends_info[$i]; // get temp array of current friend $firstName = $temp_array['first_name'];// get current name $lastName = $temp_array['last_name'];// get current name $temp = $friends[$i]; // get current id echo "$temp $firstName $lastName<br>"; // print all info $i++; // increment counter }
 
 
 One thing I wanted to add. In my $request_array, you can add any of the following in any order, and get back the information for any number of user id's you search for
 
 I am out for the night.Code:$profile_field_array = array( "about_me", "activities", "affiliations", "birthday", "books", "current_location", "education_history", "first_name", "hometown_location", "hs_info", "interests", "is_app_user", "last_name", "meeting_for", "meeting_sex", "movies", "music", "name", "notes_count", "pic", "pic_big", "pic_small", "political", "profile_update_time", "quotes", "relationship_status", "religion", "sex", "significant_other_id", "status", "timezone", "tv", "wall_count", "work_history");
 
 
 peaceComment
- 
	
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
 Re: Calling all programmers... (possible OS project)
 
 Looks kind of intriguing. You may want to add the field for user's current location, just to have some further information for users in the system.
 
 This kind of project could be really scalable if lots of people jump aboard. (I.e. - mapping of recent posts, post counts, etc)Comment
- 
	
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
 Re: Calling all programmers... (possible OS project)
 
 oh ya definitely...Looks kind of intriguing. You may want to add the field for user's current location, just to have some further information for users in the system.
 
 This kind of project could be really scalable if lots of people jump aboard. (I.e. - mapping of recent posts, post counts, etc)
 
 the example i posted was just trying to get my feet wet. its really easy to add any of those fields.Comment
- 
	
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
 Re: Calling all programmers... (possible OS project)
 
 ok fellas...
 
 I'm going to build a sample database on my local machine to do some testing...
 
 Could ya'll post your facebook ids?
 
 They can be found in the address bar when you are viewing your own profile
 
 For example, my address bar shows:
 
 Which makes my ID 7005303Code:http://auburn.facebook.com/profile.php?id=7005303 
 
 
 I just need 4 or 5 to get some testing goingComment
- 
	
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
 Re: Calling all programmers... (possible OS project)
 
 31210715Rose City 'Til I Die
 Duuuuuuuvvvvaaaaaaaal
 Hokie Hokie Hokie Hy
 
 Member: OS Uni Snob Assoc.
 OS OT Post Champ '11
 
 Twitter: @TheGIGGAS_OS
 Xbox Live: TheGIGGAS
 3DS: 1349-7755-3870
 Comment
- 
	
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
 Re: Calling all programmers... (possible OS project)
 
 quick screenshot of me pulling the data...
 
 keep in my mind there are no styles or tables or anything like that....
 
 i'm just working with the data and the database.
 
 i have very little css experience... anyone out there have any experience in that department?
 
 here is a screen showing the some data
 
   Comment
- 
	
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
- 
	
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
 Re: Calling all programmers... (possible OS project)
 
 here is the code to do the previous screen
 
 EDIT: looks like only my php will show up.... html seems to automatically renderCode:require_once 'dbappinclude.php'; // include in all files //$friends = $facebook->api_client->friends_get(); //get all of my friend's ids $user_array = array($user); // create an array with just my id $request_array= array('first_name', 'last_name', 'pic_small'); // create an array of the data i want to request $user_info = $facebook->api_client->users_getinfo($user_array, $request_array); //make the call to get the data $temp = $user_info[0]; // setting $temp to th array in spot 0, since it only contains one array $firstName = $temp['first_name']; //parsing my name $lastName = $temp['last_name']; // parsing my name $mypic = $temp['pic_small']; $query = "SELECT * FROM os_facebook_table"; //create mysql query string $results = mysql_query($query); // make query, store results $numRows = mysql_numrows($results); // count entries in the database $i=0; while ($i < $numRows) { $facebook_ids[$i] = mysql_result($results,$i,"facebook_id"); //extract facebook_ids into an array $os_name[$i] = mysql_result($results,$i,"os_name"); // extract os_names into an array $i++; } $i = 0; // set a counter $numOfElements = count($facebook_ids); //determine number of facebook_ids $friends_info = $facebook->api_client->users_getinfo($facebook_ids, $request_array);// get info for all facebook_id's in database while ($i<$numOfElements) //loop through all ids { $temp_array = $friends_info[$i]; // get temp array of current id $firstName = $temp_array['first_name'];// get current name $lastName = $temp_array['last_name'];// get current name $pic = $temp_array['pic_small']; // get picture url if ($user == $facebook_ids[$i]) // check to see if current id is user { $status = "This is you!"; $viewLink = "http://www.facebook.com/profile.php?id=" . $facebook_ids[$i]; //create link to view profile $link = "<a href=\"$viewLink\">View My Profile</a>"; //create html code for link } else { //check to see if you are friends $areFriend_results = $facebook->api_client->friends_areFriends($user, $facebook_ids[$i]); // check to see if two id's are friends $friendResults = $areFriend_results[0]; // extract returned array $areFriends = $friendResults["are_friends"]; // extract friend status -> 1 = friends, 0 = not friends if ($areFriends == '0') // if you are not friends { $status = " You aren't friends! "; //build status text $addLink = "http://www.facebook.com/addfriend.php?id=" . $facebook_ids[$i]; //create link to add friend $link = "<a href=\"$addLink\">Add as friend!</a>"; // create html code to add friend } else { $status = "You are friends! "; // build status text $viewLink = "http://www.facebook.com/profile.php?id=" . $facebook_ids[$i]; // create link to view profile $link = "<a href=\"$viewLink\">View Profile</a>"; // create html code to view profile } } //now build table using html code ?> <table border="1"> <tr> <th rowspan="4"><img src="<?php echo $pic ?>" /></th> <td>Name</td> <td><?php echo $firstName . " " . $lastName ?> </td> </tr> <tr> <td>OS Name</td> <td><?php echo $os_name[$i] ?> </td> </tr> <tr> <td>Status</td> <td><?php echo $status ?> </td> </tr> <tr> <td>Link</td> <td><?php echo $link ?> </td> </tr> </table> <?php echo "<br><br>"; $i++; // increment counter } echo "<br><br>done"Comment

 
		
	 Looking forward to the code, would be something interesting to do.
 Looking forward to the code, would be something interesting to do.  
							
						 
		
	 
		
	 
							
						
Comment