Facebook/OS Integration

Collapse

Recommended Videos

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • p2xgamers
    All Star
    • Jul 2002
    • 4735

    #16
    Re: Calling all programmers... (possible OS project)

    Originally posted by dagger55
    Facebook has released the api on the facebook developer site.

    it is written in php5.


    we could use the help! I've been working on some sample stuff... I'll try to get something posted soon.
    Ah I think I mis-read the post. Looking forward to the code, would be something interesting to do.
    Lifelong Bengals and Buckeyes fan...yeah...

    My Blog

    Comment

    • dagger55
      No end in sight...
      • Jul 2004
      • 7907

      #17
      Re: Calling all programmers... (possible OS project)

      Originally posted by p2xgamers
      Ah I think I mis-read the post. Looking forward to the code, would be something interesting to do.
      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:

      Code:
      Array ( [0] => Array ( [uid] => 7005303 [first_name] => Kevin [last_name] => Harwood ) )
      Now, that last line of code
      Code:
      $firstName = $user_info["first_name"];
      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?


      EDIT: Figured it out. The function users_getinfo() returns an array of arrays... that was my problem

      Comment

      • dagger55
        No end in sight...
        • Jul 2004
        • 7907

        #18
        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

        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");
        I am out for the night.


        peace

        Comment

        • GBrushTWood
          Banned
          • Mar 2003
          • 1624

          #19
          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

          • dagger55
            No end in sight...
            • Jul 2004
            • 7907

            #20
            Re: Calling all programmers... (possible OS project)

            Originally posted by GBrushTWood
            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)
            oh ya definitely...

            the example i posted was just trying to get my feet wet. its really easy to add any of those fields.

            Comment

            • dagger55
              No end in sight...
              • Jul 2004
              • 7907

              #21
              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:

              Code:
              http://auburn.facebook.com/profile.php?id=7005303
              Which makes my ID 7005303


              I just need 4 or 5 to get some testing going

              Comment

              • p2xgamers
                All Star
                • Jul 2002
                • 4735

                #22
                Re: Calling all programmers... (possible OS project)

                507215790
                Lifelong Bengals and Buckeyes fan...yeah...

                My Blog

                Comment

                • Beantown
                  #DoYourJob
                  • Feb 2005
                  • 31523

                  #23
                  Re: Calling all programmers... (possible OS project)

                  17606175

                  This looks really intruiging. I'm just computer illiterate, when it comes to sites and programs and such, so I wouldn't be much help other than a test-subject.

                  Comment

                  • The GIGGAS
                    Timbers - Jags - Hokies
                    • Mar 2003
                    • 28474

                    #24
                    Re: Calling all programmers... (possible OS project)

                    31210715
                    Rose 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

                    • bjf1377
                      Lurker
                      • Jul 2002
                      • 6620

                      #25
                      Re: Calling all programmers... (possible OS project)

                      23321499

                      Comment

                      • cooldude
                        Please don't go.
                        • Jul 2002
                        • 4091

                        #26
                        Re: Calling all programmers... (possible OS project)

                        1631160007

                        Comment

                        • dagger55
                          No end in sight...
                          • Jul 2004
                          • 7907

                          #27
                          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

                          • dagger55
                            No end in sight...
                            • Jul 2004
                            • 7907

                            #28
                            Re: Calling all programmers... (possible OS project)

                            added links to view a profile if you are friends, and a link to add to friends if you are not friends

                            Comment

                            • dagger55
                              No end in sight...
                              • Jul 2004
                              • 7907

                              #29
                              Re: Calling all programmers... (possible OS project)

                              trying to put some data into tables...



                              EDIT: just noticed a little glitch there with people who are friends (dieselboy in this example)

                              Got that fixed now
                              Last edited by dagger55; 05-27-2007, 02:47 PM.

                              Comment

                              • dagger55
                                No end in sight...
                                • Jul 2004
                                • 7907

                                #30
                                Re: Calling all programmers... (possible OS project)

                                here is the code to do the previous screen

                                Code:
                                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"
                                EDIT: looks like only my php will show up.... html seems to automatically render

                                Comment

                                Working...