Jump to content


Photo

Php Twitter Search Api

php twitter epitwitter

  • Please log in to reply
4 replies to this topic

#1 itsjimmy91

itsjimmy91

    Newbie

  • New Members
  • Pip
  • 4 posts

Posted 07 December 2012 - 11:26 PM

Hey guys. I'm new here and pretty new to PHP. I know the basics of the language and can do most simple things, but I am working with Twitter in a project now and I have never worked with it before in terms of PHP.

I have a PHP page that simply provides a link that the user clicks on to go to the Twitter page where they are asked to grant access to my application to use their Twitter. I do this through oAuth and this works as it should, returning a token. Upon granting access, a user is sent to a new PHP page which simply asks them to enter a search term.

Once they enter a search term, I want to take that term and simply run it through the Twitter Search API. I then want to grab all of the IDs of the Tweets returned and store them.

Here is the code that I have:

<?php
session_start();
ob_start();
include 'lib/EpiCurl.php';
include 'lib/EpiOAuth.php';
include 'lib/EpiTwitter.php';
include 'lib/secret.php';

$oauth_token = $_POST['authtoken'];
$search = $_POST['searchterm'];
$tweets = $_POST['tweets'];
$url = 'http://api.search.twitter.com/search.json?q='.$searchterm;

$twitterObj = new EpiTwitter($consumer_key, $consumer_secret);
$twitterObj->setToken($oauth_token);
$token = $twitterObj->getAccessToken();
$twitterObj->setToken($token->oauth_token, $token->oauth_token_secret);
$_SESSION['ot'] = $token->oauth_token;
$_SESSION['ots'] = $token->oauth_token_secret;
$twitterInfo = $twitterObj->get_accountVerify_credentials();
$twitterInfo->response;

$creds = $twitterObj->get($url);
?>

Now I'm stuck with what $creds is actually holding and how I will get the Tweet ID's out of it. I've tried a bunch of echo statements to attempt to figure it out, but I can't seem to get it. I feel like I'm close.

Thanks for any help.

#2 Christian F.

Christian F.

    Advanced Member

  • Staff Alumni
  • 3,106 posts
  • LocationNorway

Posted 08 December 2012 - 01:31 AM

var_dump () will tell you everything you need to know about what kind of data is stored in the variable. Should help you get along to the next step.
Keeping it simple.

#3 itsjimmy91

itsjimmy91

    Newbie

  • New Members
  • Pip
  • 4 posts

Posted 08 December 2012 - 02:07 PM

Hm.. ok. I didn't know about var_dump(), that's definitely a helpful thing to know. Thanks for that.

This is what shows on the var_dump of $creds...

object(EpiTwitterJson)#7 (1) { ["resp":"EpiTwitterJson":private]=> object(EpiCurlManager)#8 (2) { ["key":"EpiCurlManager":private]=> string(14) "Resource id #8" ["epiCurl":"EpiCurlManager":private]=> object(EpiCurl)#2 (6) { ["mc":"EpiCurl":private]=> resource(5) of type (curl_multi) ["msgs":"EpiCurl":private]=> NULL ["running":"EpiCurl":private]=> NULL ["requests":"EpiCurl":private]=> array(3) { ["Resource id #6"]=> resource(6) of type (curl) ["Resource id #7"]=> resource(7) of type (curl) ["Resource id #8"]=> resource(<img src='http://forums.phpfreaks.com/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='8)' /> of type (curl) } ["responses":"EpiCurl":private]=> array(2) { ["Resource id #6"]=> array(5) { ["data"]=> string(167) "oauth_token=281896160-64tXSSB0Wd8qkw8HgvL125VBWyQN3zCigkfXb2ZY&oauth_token_secret=ZF9hnkCMRlRbnSZvIZEYCshqrLuR79paa4Vc1M8EyzQ&user_id=281896160&screen_name=jimmyhalter" ["code"]=> int(200) ["time"]=> float(0.29566) ["length"]=> float(167) ["type"]=> string(24) "text/html; charset=utf-8" } ["Resource id #7"]=> array(5) { ["data"]=> string(68) "{"errors":[{"message":"Sorry, that page does not exist","code":34}]}" ["code"]=> int(404) ["time"]=> float(0.115966) ["length"]=> float(68) ["type"]=> string(31) "application/json; charset=utf-8" } } ["properties":"EpiCurl":private]=> array(4) { ["code"]=> int(2097154) ["time"]=> int(3145731) ["length"]=> int(3145743) ["type"]=> int(1048594) } } } }

I'm really not sure what to do with this.

#4 Christian F.

Christian F.

    Advanced Member

  • Staff Alumni
  • 3,106 posts
  • LocationNorway

Posted 09 December 2012 - 12:30 AM

If you click on "View source" you'll get a much easier to read representation.
That said, you'll need to pursue the documentation for the class you've used, in order to find out how to pull the tweet IDs from the twitter account. What you've done above is just to authenticate against the account.

Speaking of authentication: You'll need to generate a new oAuth secret key now, seeing as how you just posted it publicly available to the entire internet.
Keeping it simple.

#5 itsjimmy91

itsjimmy91

    Newbie

  • New Members
  • Pip
  • 4 posts

Posted 10 December 2012 - 03:47 PM

oof .. I guess that was a rookie mistake. The View Source actually helps a ton, hopefully I can figure it out with that. Thank you.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com