| Project: | |
| Version: | 6.x-3.x-dev |
| Component: | Twitter API |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Issue Summary
I'm working on a site that calls for us to allow one admin user only to enter Twitter account credentials, and then for us to fetch that account's friends timeline (essentially) and show it in a block. Everything worked great except that when I used $twitter->friends_timeline(), I ended up fetching a bunch of tweets by users whose Twitter accounts were not stored in the local DB, thus causing their screen_name field to be blank in the Views integration.
To solve this, I had to also fetch a list of the account friends using the API "statuses/friends" method, so I added a "friends" method to the Twitter class to support this. A simple patch is attached.
Here is some sample driver code (taken from the module I wrote to accomplish what I described above):
<?php
define('ADMIN_TWTTIER_ID', '12345678');
function mymodule_cron() {
if (!module_exists('twitter')) {
return;
}
module_load_include('inc', 'twitter');
$account = twitter_account_load(ADMIN_TWTTIER_ID);
$twitter = twitter_connect($account);
$friends = $twitter->friends();
foreach ($friends as $friend) {
$friend->uid = 0; // To prevent it from being linked to any logged-in user.
twitter_account_save($friend);
}
$tweets = $twitter->friends_timeline();
foreach ($tweets as $tweet) {
twitter_status_save($tweet);
}
}
?>
Comments
#1