Viewed   72 times

How would I go about pulling in tweets from multiple twitter users with PHP and displaying them as part of one combined list on my page?



Use the search API and boolean OR operator. For example here is the URL for CNN Breaking News and NPR All Things Considered:

The query is URLEncoded so use Fiddler Tools -> Text Encode/Decode or your favorite tool to see that the correct format in plain text is:


Hope that helps.

Monday, November 28, 2022

If your of followers is greater than 5000 then $aFollowers = $oTwitter->get('followers/ids'); will only return the first 5000 ids. In what order? Twitter does not guarantee any order, so we'll just assume random.

If the following check $isFollowing = in_array( $iFollowing, $aFollowers );, the person $iFollowing may or may not be in the list $aFollowers depending on how Twitter returned the followers to you. If the person is in the first 5000, then this will work, if they're outside the first 5000 then the check will fail, even if the person is legitimately following you.

You'll need to pull all your followers via cursors. Check out the doc on cursors / pages - will help you out a bit. Basically you need to do this.

$aFollowers = array();
$cursor = -1;
do {
  $follows = $oTwitter->get('followers/ids?cursor=' . $cursor);
  $aFollowers = array_merge($follows->ids, $aFollowers);
  $cursor = $follows->next_cursor;
} while ($cursor > 0);
Wednesday, November 30, 2022

It looks like your problem is that your sending your base64 encoded username/password in the soap header. It actually needs to be included in the http header. My solution is in ruby but hopefully it can help you out.

soap_client = Savon.client(
  endpoint: "", 
  namespace: "", 
  headers: { "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" }, 
  env_namespace: :soapenv, 
  namespace_identifier: :ser, 
  ssl_verify_mode: :none

message = { 
  "lookupCriteria" => {
"criteria" => {
      "field" => "email_address",
      "value" => ""

response =, message: message)
p response.body

So your XML ends up looking like this.

SOAP request:
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==, SOAPAction: "getContactRecords",
Content-Type: text/xml;charset=UTF-8, Content-Length: 471

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:xsd="" xmlns:xsi="" xmlns:ser="" xmlns:soapenv="">

HTTPI POST request to (httpclient)
SOAP response (status 200)

<env:Envelope xmlns:env=''>
    <ns2:getContactRecordsResponse xmlns:ns2="" xmlns:ns3="">
Friday, August 5, 2022

Check out the Twitter API console ( )

.. and hack it a little bit because its undocumented from the console standpoint.

Go to users/show where you'll see this{screen_name}

change it to this{id}

I.E for the ID of @TwitterAPI (6253282) this call

will get you this:

  "id": 6253282,
  "id_str": "6253282",
  "name": "Twitter API",
  "screen_name": "twitterapi",
  "location": "San Francisco, CA",
Saturday, August 20, 2022

I think

$twitter_path = '1.1/statuses/retweet.json';

doesn't exist, you can use :

$twitter_path = '1.1/statuses/retweet/' . $_GET['t_id'] . '.json';

But, without parameters in your request

$http_code = $connection->request('POST', $connection->url($twitter_path));

Link to the official documentation

Friday, December 2, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :