Asked  7 Months ago    Answers:  5   Viewed   38 times

In API 1.0, we can use users/profile_image/:screen_name

For example :

But, it doesn't work anymore in API 1.1.

Do you have a solution, please ?



The user's profile image

Okay, so you want a user's profile image. You're going to need to take a look at the twitter REST API 1.1 docs. This is a list of all the different requests you can make to their API (don't worry, I'll get to how you actually do this later on).

There are multiple ways to get the user's profile image, but the most notable one is: users/show. According to the docs for this, the users/show method:

Returns a variety of information about the user specified by the required user_id or screen_name parameter. The author's most recent Tweet will be returned inline when possible.

Well, the user profile image must be in there somewhere, correct?

Let's have a look at a typical response to a request for this information, using the users/show url (we'll use my profile as an example).

Example response for users/show from the twitter 1.1 api

I've cut off some from the bottom, because there is a lot of data to go through. Most importantly, you'll see what you require:

profile_image_url key

This is the profile_image_url key that you need to get access to.

So, how do you do all this? It's pretty simple, actually.

Authenticated Requests

As you rightly pointed out, as of June 11th 2013 you can't make unauthenticated requests, or any to the 1.0 API any more, because it has been retired. So OAuth is the way to make requests to the 1.1 API.

I wrote a stack overflow post with an aim to help all you guys make authenticated requests to the 1.1 API with little to no effort.

When you use it, you'll get back the response you see above. Follow the posts instructions, step-by-step, and you can get the library here (you only need to include one file in your project).

Basically, the previous post explains that you need to do the following:

  • Create a twitter developer account
  • Get yourself a set of unique keys from twitter (4 keys in total).
  • Set your application to have read/write access
  • Include TwitterApiExchange.php (the library)
  • Put your keys in a $settings array
  • Choose your URL and request method (Post/Get) from the docs (I put the link above!)
  • Make the request, that's it!

A practical example

I'm going to assume you followed the step-by-step instructions in the above post (containing pretty colour pictures). Here's the code you would use to get what you want.

// Require the library file, obviously

// Set up your settings with the keys you get from the dev site
$settings = array(
    'oauth_access_token' => "YOUR_ACCESS_TOKEN",
    'oauth_access_token_secret' => "YOUR_ACCESS_TOKEN_SECRET",
    'consumer_key' => "YOUR_CONSUMER_KEY",
    'consumer_secret' => "YOUR_CONSUMER_SECRET"

// Chooose the url you want from the docs, this is the users/show
$url = '';
// The request method, according to the docs, is GET, not POST
$requestMethod = 'GET';

// Set up your get string, we're using my screen name here
$getfield = '?screen_name=j7mbo';

// Create the object
$twitter = new TwitterAPIExchange($settings);

// Make the request and get the response into the $json variable
$json =  $twitter->setGetfield($getfield)
                 ->buildOauth($url, $requestMethod)

// It's json, so decode it into an array
$result = json_decode($json);

// Access the profile_image_url element in the array
echo $result->profile_image_url;

That's pretty much it! Very simple. There's also users/lookup which effectively does the same thing, but you can:

Returns fully-hydrated user objects for up to 100 users per request, as specified by comma-separated values passed to the user_id and/or screen_name parameters.

If you ever need to get more than one user's details, use that, but as you only require one user's details, use users/show as above.

I hope that cleared things up a bit!

Wednesday, March 31, 2021
answered 7 Months ago

"my contact form downloads the PHP script rather than sending the email"

It sounds like PHP is either not installed/running or not properly configured.

I suggest that you create a file called test.php file with <?php echo "Hello world"; ?> inside it and see if it does the same thing.

If it still wants to appear like it wants to download, then there's the problem; PHP is not installed or not properly configured and isn't parsing PHP as it normally should.

Create another file and place <?php phpinfo(); ?> and it should show you the server's information.

Wednesday, March 31, 2021
answered 7 Months ago

Finally, I found a solution.

All you need to do is, once you get the callback, initialize the class again with new access token.

$connection = new TwitterOAuth('MY_CONSUMER_KEY', 'MY_CONSUMER_SECRET', $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);

$access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $_REQUEST['oauth_verifier']));

$connection = new TwitterOAuth('MY_CONSUMER_KEY', 'MY_CONSUMER_SECRET', $access_token['oauth_token'], $access_token['oauth_token_secret']);

I don't know why that works, but it does work like a charm. Found this solution from here.

Saturday, May 29, 2021
answered 5 Months ago

First, you need to Authenticate your request (Get permission).

second, see follow these steps:

1.Download FHSTwitterEngine Twitter Library.

2.Add the folder FHSTwitterEngine" to your project and #import "FHSTwitterEngine.h".

3.add SystemConfiguration.framework to your project.

Usage : the [ViewDidLoad] add the following code.

UIButton *logIn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    logIn.frame = CGRectMake(100, 100, 100, 100);
    [logIn setTitle:@"Login" forState:UIControlStateNormal];
    [logIn addTarget:self action:@selector(showLoginWindow:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:logIn];

[[FHSTwitterEngine sharedEngine]permanentlySetConsumerKey:@"<consumer_key>" andSecret:@"<consumer_secret>"];
    [[FHSTwitterEngine sharedEngine]setDelegate:self];

and don't forget to import the delegate FHSTwitterEngineAccessTokenDelegate.

  1. you need to get the permission for your request, with the following method which will present Login window:
- (void)showLoginWindow:(id)sender {
    [[FHSTwitterEngine sharedEngine]showOAuthLoginControllerFromViewController:self withCompletion:^(BOOL success) {
        NSLog(success?@"L0L success":@"O noes!!! Loggen faylur!!!");

when the Login window is presented, enter your Twitter Username and Password to authenticate your request.

  1. add the following methods to your code:
    [super viewWillAppear:animated];
    [[FHSTwitterEngine sharedEngine]loadAccessToken];
    NSString *username = [[FHSTwitterEngine sharedEngine]loggedInUsername];// self.engine.loggedInUsername;
    if (username.length > 0) {
        lbl.text = [NSString stringWithFormat:@"Logged in as %@",username];
        [self listResults];

    } else {
        lbl.text = @"You are not logged in.";

- (void)storeAccessToken:(NSString *)accessToken {
    [[NSUserDefaults standardUserDefaults]setObject:accessToken forKey:@"SavedAccessHTTPBody"];

- (NSString *)loadAccessToken {
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"SavedAccessHTTPBody"];

4.Now you are ready to get your request, with the following method(in this method I created a Twitter search for some Hashtag, to get the screen_name for example):

- (void)listResults {

    dispatch_async(GCDBackgroundThread, ^{
        @autoreleasepool {
            [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

        // the following line contains a FHSTwitterEngine method wich do the search.

            dict = [[FHSTwitterEngine sharedEngine]searchTweetsWithQuery:@"#iOS" count:100 resultType:FHSTwitterEngineResultTypeRecent unil:nil sinceID:nil maxID:nil];
          // NSLog(@"%@",dict);
            NSArray *results = [dict objectForKey:@"statuses"];

          //  NSLog(@"array text = %@",results);
            for (NSDictionary *item in results) {
                NSLog(@"text == %@",[item objectForKey:@"text"]);
                NSLog(@"name == %@",[[item objectForKey:@"user"]objectForKey:@"name"]);
                NSLog(@"screen name == %@",[[item objectForKey:@"user"]objectForKey:@"screen_name"]);
                NSLog(@"pic == %@",[[item objectForKey:@"user"]objectForKey:@"profile_image_url_https"]);

            dispatch_sync(GCDMainThread, ^{
                @autoreleasepool {
                    UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"Complete!" message:@"Your list of followers has been fetched" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                    [av show];
                    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

That's all. I just got the screen_name from a search Query, you can get a timeline for a user using the following methods:

// statuses/user_timeline
- (id)getTimelineForUser:(NSString *)user isID:(BOOL)isID count:(int)count;
- (id)getTimelineForUser:(NSString *)user isID:(BOOL)isID count:(int)count sinceID:(NSString *)sinceID maxID:(NSString *)maxID; 

instead of the search method above.

Note: see the FHSTwitterEngine.h to know what method you need to use. Note: to get the <consumer_key> and the <consumer_secret> you need to to visit this link to register your app in Twitter.

Thursday, July 1, 2021
answered 4 Months ago

i found that querying the stream for a global bounding box, returns only status withs geo location. So this worked:

// cb is an instace of ConfigurationBuilder
TwitterStream twitter = new TwitterStreamFactory(;
FilterQuery filtro = new FilterQuery();    
double[][] bb= {{-180, -90}, {180, 90}};

returning only tweets with location info.

Sunday, August 15, 2021
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :