Jump to content

php_lover

Members
  • Posts

    13
  • Joined

  • Last visited

php_lover's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. the two different api code for facebook, google + and twitter is located in three respective different folders , facebook folder for the facebook api , twitter folder for twitter and google_plus.. The thing is , I'm trying to make people be able to log through Twitter and access the application .. and give them the option to also logon through Facebook after logging through Twitter and keep the twitter-based data after they logged through Facebook , I would basically like them to be able to view both their twitter and facebook feeds and other data mixed together at the same time ... I tried to implement sessions , but it looks like if they log through Facebook after logging through twitter first , the Twitter session variable content become NULL and only facebook session data is displayed .. How can I manipulate the sessions so that twitter session data can be kept when a user log through facebook as well ? Below is what I did to test the data .. session_set_cookie_params('3600'); session_start(); require('../database/connection.php'); require_once('../twitter/twitteroauth/twitteroauth.php'); require_once('../twitter/config.php'); include_once '../facebook/fbmain.php'; // Here I'll test the $_SESSION variable to see if twitter data is kept after a user logs through facebook as well .. but twitter data become NULL instead and the $_SESSION array only show facebook data .. How can I make twitter session data STAY after someone logs through facebook as well ? var_dump($_SESSION); var_dump(session_id()); // twitter session data gets overriden by facebook data although the variable names are different .. /* If access tokens are not available redirect to connect page. */ if (empty($_SESSION['facebook_id']) && (empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret']))) { header('Location: ./clearsessions.php'); } else { /* Get user access tokens out of the session. */ $access_token = $_SESSION['access_token']; /* Create a TwitterOauth object with consumer/user tokens. */ $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']); /* If method is set change API call made. Test is called by default. */ $content = $connection->get('account/verify_credentials'); $json = json_encode($content); $data = json_decode($json,true); $screen_name = $data["screen_name"]; $name = $data["name"]; $image_url = $data['profile_image_url']; $_SESSION['screen_name'] = $screen_name; $_SESSION['image_url'] = $image_url; $query = "SELECT * FROM Users WHERE username ='$screen_name'"; $result = mysql_query($query); $result_count = mysql_num_rows($result); if($result_count == 0) { $insert = "INSERT INTO Users(username) VALUES('$screen_name')"; $result_insert = mysql_query($insert); } } if(isset($_SESSION['oauth_token']) && isset($_SESSION['oauth_token_secret']) && isset($_SESSION['facebook_id'])){ $user = $_SESSION['facebook_id']; } ?>
  2. How though ? Isn't the user supposed to connect to facebook , google , twitter via their APIs ... It's too brief , maybe if you elaborate on the process , that'd be great ... because to connect to facebook , google , twitter to pull the feeds, statuses , images , etc ... you need the APIs , and that's what I'm implementing .. I'm having trouble if the facebook api session overwritting the twitter session ..
  3. Hello Oaass, I am not quite sure I understand what you mean ... How can users view feeds from Twitter , Facebook and Google+ networks , if I don't let them connect through Facebook , Twitter and Google+ via their APIs to pull data .. Could you tell me explain a little bit more what you meant , I'd totally apppreciate it ..
  4. Ok , so I am developing a web application that's going to let people connect through Facebook , Twitter or Google plus ... Now , the api code is located in three respective different folders , facebook folder for the facebook api , twitter folder for twitter and google_plus.. The thing is , I'm trying to make people be able to log through Twitter and access the application .. and give them the option to also logon through Facebook after logging through Twitter and keep the twitter-based data after they logged through Facebook , I would basically like them to be able to view both their twitter and facebook feeds mixed together at the same time ... I tried to implement sessions , but it looks like if they log through Facebook after logging through twitter first , the Twitter session variable content become NULL and only facebook session data is displayed .. How can I manipulate the sessions so that twitter data can be kept when a user log through facebook as well ? Below is what I did to test the data .. <?php session_set_cookie_params('3600'); session_start(); require('../database/connection.php'); require_once('../twitter/twitteroauth/twitteroauth.php'); require_once('../twitter/config.php'); include_once '../facebook/fbmain.php'; // Here I'll test the $_SESSION variable to see if twitter data is kept after a user logs through facebook as well .. but twitter data become NULL instead and the $_SESSION array only show facebook data .. How can I make twitter session data STAY after someone logs through facebook as well ? var_dump($_SESSION); var_dump(session_id()); /* If access tokens are not available redirect to connect page. */ if (empty($_SESSION['facebook_id']) && (empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret']))) { header('Location: ./clearsessions.php'); } else { /* Get user access tokens out of the session. */ $access_token = $_SESSION['access_token']; /* Create a TwitterOauth object with consumer/user tokens. */ $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']); /* If method is set change API call made. Test is called by default. */ $content = $connection->get('account/verify_credentials'); $json = json_encode($content); $data = json_decode($json,true); $screen_name = $data["screen_name"]; $name = $data["name"]; $image_url = $data['profile_image_url']; $_SESSION['screen_name'] = $screen_name; $_SESSION['image_url'] = $image_url; $query = "SELECT * FROM Users WHERE username ='$screen_name'"; $result = mysql_query($query); $result_count = mysql_num_rows($result); if($result_count == 0) { $insert = "INSERT INTO Users(username) VALUES('$screen_name')"; $result_insert = mysql_query($insert); } } if(isset($_SESSION['oauth_token']) && isset($_SESSION['oauth_token_secret']) && isset($_SESSION['facebook_id'])){ $user = $_SESSION['facebook_id']; } ?>
  5. Ok , there is an issue with the rotten tomatoes API , It gives developers the ability to set a limit of movies to return from the API from a specific category , like the movies in the box office are pulled dynamically, but when I set the limit to 50 , or even 10 movies , it only returns an array containing 3 movies instead of 10 or 50 or whatever the limit of movies is in the API call ... What could be causing that ? is there maybe something wrong with the way I am using the file_get_contents function $box_office_movies = file_get_contents('http://api.rottentomatoes.com/api/public/v1.0/lists/movies/box_office.json?limit=50&country=us&apikey=[key]',FILE_USE_INCLUDE_PATH); $box_office_movies = json_decode($box_office_movies, true); var_dump($box_office_movies); // returns only 3 movies ..
  6. Kicken , I tried your method and it's not working ... Although the php script to get the images redirect to the image link of the twitter user , it doesn't show the image with the img tag ... My suspicion is because the img tag executes fast and doesn't wait for the PHP script to finish doing its job ... Thanks for trying to help though.
  7. I think I get what you were trying to tell me after re-reading your code .. Let me try this and I'll get back to you .. Thanks a bunch
  8. Question though .. since you're passing parameters to the <img> tag .. wouldn't that have to be a URL for it to work ? I'd like the image to be displayed without having to click on it to go to the processing script ? hope I am not confusing you .
  9. Hello Ignance .. Thank you so much for taking the time to respond ... I see that you're from Belgium .. I have a brother there and je parle francais aussi :-) I am not sure I quite understand what you were trying to tell me ... As you can see , I try to fetch images from multiple users inside a loop based on the twitter username of the user I pass to the twitter API service in order to return the image .. The url generated by the API is this one https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi&count=1 .. Is there a way I can pass this link through Jquery AJAX and get the images much quicker instead of waiting for minutes for the php to return the data because the page keeps loading for a minute . I'm so new to the Jquery & AJAX world .. How would you use the url above to fetch the images , yet embed it in the PHP code I have ? Your response would be much appreciated , and if I misunderstood what you were explaining , please let me know :-)
  10. First of all , thanks for taking the time to try to help .. but the problem is this one , I'm basically trying to get the images of all the twitter user names inside the while loop , the twitter usernames of the users whose images I want to fetch through the twitter API , so I'm not quite sure how the script you wrote above would speed up the process of getting all the images , if you look at my code in my question , I first query my local MYSQL database to get the twitter usernames , and then make a request to the twitter API to return the profile image of the the user whose twitter username I passed to the API .. Does this make sense ? so this is an example of the link generated by the API which returns data ... How can I make it faster with AJAX using this url instead ? https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi&count=1
  11. Hello Letter E , thanks for taking the time to answer .. But how would I make an asynchronous call to the twitter API .. I'm only used to PHP .. Could you give me a hint or an example if you dont mind ? I'd appreciate it a lot . Thanks !!
  12. So I have this PHP script below that requests data from the Twitter API and then displays it on the page according to the information that I have in my local database because I stored twitter usernames of some twitter users so I can pass them to the API and display the profile images of those twitter users. The script works fine to display my request from the API but it is AWFULLY slow , so I was wondering what could cause the script to be so slow ... Below is my script .. the first part seems to execute fine... /* Create a TwitterOauth object with consumer/user tokens. */ $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']); $url = $connection->get('statuses/user_timeline', array('screen_name' => $row['Twitter'],count=>'1')); $results = json_encode($url); $data = json_decode($results, true); $image = ''; if(is_array($data)){ $image = $data[0]['user']['profile_image_url']; $image_bigger = str_replace('_normal', '_bigger',$image); } echo "<h1 align='middle' id = $id> $name Vs Opposition </h1>"; echo "<img src='".$image_bigger."' width= '100' height ='100' class= 'image' align='middle' />"; ?> //This part of the script below seems to be the culprit of the page taking so long to display info because it loops through all the twitter IDs returned by the query in order to display the images of the authors that I request through the API inside the loop . $data2 variable is very long array of info regarding the twitter user and from that array , I pick the key of the array containing the value that stores the picture of every twitter user inside a loop .. How could I dynamically optimize this so I can get all those images ? <?php $select2 = "SELECT * FROM AUTHORS WHERE ID <> $id"; $result2 = mysql_query($select2); $result_count = mysql_num_rows($result2); $image_array = array(); $unique_id = array(); $counter = 0; if($result_count > 0) { while ($row2 = mysql_fetch_array($result2, MYSQL_ASSOC)) { array_push($unique_id, $row2['ID']); $url2 = $connection->get('statuses/user_timeline', array('screen_name' => $row2['Twitter'],count=>'1')); $results2 = json_encode($url2); $data2 = json_decode($results2, true); // data through is a very long array $image2 = $data2[$counter]['user']['profile_image_url']; $image3 = str_replace('_normal', '_bigger',$image2); array_push($image_array,$image3); } } var_dump($data2); exit; ?> <div id="test"> <iframe id="frame" src="" width="100%" height="100% frameBorder="0" "> </iframe> </div> <div id ="opposition"> <?php $unique_image = array_unique($image_array); $id_array = array_unique($unique_id); $i = 0; foreach($unique_image as $content) { echo "<a id ='".$id_array[$i]."' href ='#'><img src='".$content."' width= '100' height ='100' class='image' /></a>"; $i++; } ?> </div>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.