PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 2nd, 2013, 04:50 PM
PHP_lover_85 PHP_lover_85 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 PHP_lover_85 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 17 sec
Reputation Power: 0
PHP5 - How can I get both Facebook and Twitter data on the same page through API calls ?

I haven't been successful to receive help on this one on stackoverflow before, I already know how to pull tweets using the twitter API and how to pull facebook statuses using the Graph API .My question is this one ...and I know it's technically possible because klout.com does it . I would like to be able to let users of my websites sign in through Twitter , get the tweets of the people they follow , which already works, But at the same time , once already logged in with Twitter , I'd like to give them the option to connect to their facebook accounts , and view their FACEBOOK statuses ON TOP of their tweets of twitter and display both the tweets and FB statuses on the same page .It's technically possible because when I log on klout.com through twitter, it gives me the option to connect my facebook account and see both my twitter and facebook data . Below is the code I tried to implement but it won't work !!



Code:
// This twitter part works once logged in through twitter.
<?php
session_start();
require_once ('../madscore/twitter/twitteroauth/twitteroauth.php');
require_once ('../madscore/twitter/config.php');
require ('../madscore/database/connect.php');
/* If access tokens are not available redirect to connect page. */
if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) {
    header('Location: ./clearsessions.php');
}
/* Get user access tokens out of the session. */
$access_token = $_SESSION['access_token'];
/* Create a TwitterOauth object with consumer/user tokens. */
$handle = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
?>

       // This is the part where I call the authentications service for Facebook through the require authentication.php file , which I also copied and pasted below.
        <?php
require "../madscore/authentication.php";
// $config['baseurl'] ="../index3.php";
//if user is logged in and session is valid.
if ($fbme) {
    //Retriving movies those are user like using graph api
    try {
        $movies = $facebook->api('/me/movies');
        $pages = $facebook->api('/me/likes');
    }
    catch(Exception $o) {
        d($o);
    }
    //Calling users.getinfo legacy api call example
    try {
        $param = array('method' => 'users.getinfo', 'uids' => $fbme['id'], 'fields' => 'name,current_location,profile_url', 'callback' => '');
        $userInfo = $facebook->api($param);
    }
    catch(Exception $o) {
        d($o);
    }
    //update user's status using graph api
    if (isset($_POST['tt'])) {
        try {
            $statusUpdate = $facebook->api('/me/feed', 'post', array('message' => $_POST['tt'], 'cb' => ''));
        }
        catch(FacebookApiException $e) {
            d($e);
        }
    }
    //fql query example using legacy method call and passing parameter
    try {
        //get user id
        $uid = $facebook->getUser();
        //or you can use $uid = $fbme['id'];
        $fql = "SELECT pic_square
        FROM user 
        WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";
        $param = array('method' => 'fql.query', 'query' => $fql, 'callback' => '');
        $fqlResult = $facebook->api($param);
    }
    catch(Exception $o) {
        d($o);
    }
}
?>

        // This displays my twitter followers , and it works .. but below this code when i try to actually display data from facebook , nothing happens ..
        <?php
$followers = $handle->get('friends/list', array('screen_name' => $screen_name));
$json = json_encode($followers);
$array = json_decode($json, true);
shuffle($array);
if (is_array($array)) {
    foreach ($array as $value) {
        if (is_array($value)) {
            foreach ($value as $key => $second) {
                if (is_array($second)) {
                    foreach ($second as $key_second => $third) if ($key_second != 'profile_image_url') {
                        unset($key_second);
                    } else {
                        echo "<img src='" . $third . "' width='100' height='100'/>";
                    }
                }
            }
        }
    }
}
?>





 //Testing if facebook data gets returned here .. nothing happens ..

<?php var_dump($fbme); ?>

//this is the authentication file from the require statement for facebook(authentication.php)

<?php
$fbconfig['appid'] = "314216702389099";
$fbconfig['api'] = "314286708589099";
$fbconfig['secret'] = "8f803e0f9e9da4f2ba9f23ad3bd00ded";
try {
    include_once "../madscore/facebook/facebook-sdk/src/facebook.php";
}
catch(Exception $o) {
    echo '<pre>';
    print_r($o);
    echo '</pre>';
}
// Create our Application instance.
$facebook = new Facebook(array('appId' => $fbconfig['appid'], 'secret' => $fbconfig['secret'], 'cookie' => true,));
// We may or may not have this data based on a $_GET or $_COOKIE based session.
// If we get a session here, it means we found a correctly signed session using
// the Application Secret only Facebook and the Application know. We dont know
// if it is still valid until we make an API call using the session. A session
// can become invalid if it has already expired (should not be getting the
// session back in this case) or if the user logged out of Facebook.
$session = $facebook->getUser();
$fbme = null;
// Session based graph API call.
if ($session) {
    try {
        $uid = $facebook->getUser();
        $fbme = $facebook->api('/me');
    }
    catch(FacebookApiException $e) {
        // d($e);

    }
}
function d($d) {
    echo '<pre>';
    print_r($d);
    echo '</pre>';
}
?>

Reply With Quote
  #2  
Old January 2nd, 2013, 05:43 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,723 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 7 h 52 m 46 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
"On the same page" is literally what they do. There's no magical API call or something (at least that I've ever heard of): they sign you in to Twitter, grab information, sign you in to Facebook, grab information, and simply display it all at once.

Reply With Quote
  #3  
Old January 2nd, 2013, 08:38 PM
PHP_lover_85 PHP_lover_85 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 PHP_lover_85 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 17 sec
Reputation Power: 0
Quote:
Originally Posted by requinix
"On the same page" is literally what they do. There's no magical API call or something (at least that I've ever heard of): they sign you in to Twitter, grab information, sign you in to Facebook, grab information, and simply display it all at once.


Yes , so I tried to do it in the script above but it's only displaying the twitter DATA , not the facebook data .. where did I go wrong ? That's the help I was asking for ... I know it's technically possible because klout.com does it ... I tried to grab data from facebook but it's not displaying anything , only the twitter data.. I need help about the script above. Thanks in advance

Reply With Quote
  #4  
Old January 2nd, 2013, 08:49 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,723 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 7 h 52 m 46 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Well at first glance I'm wondering where $facebook comes from...

Get them working independently first, so you know you can retrieve the data properly. After that then you can stitch them together.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP5 - How can I get both Facebook and Twitter data on the same page through API calls ?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap