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?
Answers
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);
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: "https://api.five9.com/wsadmin/AdminWebService/",
namespace: "http://service.admin.ws.five9.com/",
headers: { "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" },
env_namespace: :soapenv,
namespace_identifier: :ser,
ssl_verify_mode: :none
)
message = {
"lookupCriteria" => {
"criteria" => {
"field" => "email_address",
"value" => "something@example.com"
}
}
}
response = soap_client.call(:getContactRecords, message: message)
p response.body
So your XML ends up looking like this.
SOAP request: https://api.five9.com/wsadmin/AdminWebService/
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="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ser="http://service.admin.ws.five9.com/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ser:getContactRecords>
<lookupCriteria>
<criteria>
<field>email_address</field>
<value>something@example.com</value>
</criteria>
</lookupCriteria>
</ser:getContactRecords>
</soapenv:Body>
</soapenv:Envelope>
HTTPI POST request to api.five9.com (httpclient)
SOAP response (status 200)
<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
<env:Header></env:Header>
<env:Body>
<ns2:getContactRecordsResponse xmlns:ns2="http://service.admin.ws.five9.com/" xmlns:ns3="http://service.admin.ws.five9.com/v1/">
<return>
<fields>number1</fields>
<fields>email_address</fields>
<records>
<values>
<data>5555555555</data>
<data>something@example.com</data>
</values>
</records>
</return>
</ns2:getContactRecordsResponse>
</env:Body>
</env:Envelope>
Check out the Twitter API console ( https://dev.twitter.com/console )
.. and hack it a little bit because its undocumented from the console standpoint.
Go to users/show
where you'll see this
http://api.twitter.com/1/users/show.json?screen_name={screen_name}
change it to this
http://api.twitter.com/1/users/show.json?user_id={id}
I.E for the ID of @TwitterAPI (6253282) this call
http://api.twitter.com/1/users/show.json?user_id=6253282
will get you this:
{
"id": 6253282,
"id_str": "6253282",
"name": "Twitter API",
"screen_name": "twitterapi",
"location": "San Francisco, CA",
etc...
}
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
Use the search API and boolean OR operator. For example here is the URL for CNN Breaking News and NPR All Things Considered:
http://search.twitter.com/search.json?q=from%3acnnbrk+OR+from%3anpratc
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:
q=from:cnnbrk+OR+from:npratc
Hope that helps.