1

I want to get the twitter profile image. I get the ACAccount. Then I do an SLRequest. The problem is that response is empty...The app is added on the twitter developer site. I never get an OAuth token or even user the keys generated from the developer site in my app. Should I be storing an oauth token and/or using the keys anywhere? For facebook, I set the appID facebook gave me in the plist. Is it similar with twitter api key?

Edit: The response isn't empty. I think there is a binary character in it. But when I print out timelineData, it shows as empty.

-(void)slRequestTwitter:(ACAccount *)selectedTwitterAccount
{
    NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/user_timeline.json"];
    NSDictionary *params = @{@"screen_name" : selectedTwitterAccount.username,
                             @"include_rts" : @"0",
                             @"trim_user" : @"1",
                             @"count" : @"1"};
    SLRequest *request =
    [SLRequest requestForServiceType:SLServiceTypeTwitter
                       requestMethod:SLRequestMethodGET
                                 URL:url
                          parameters:params];
    //Attach account to request
    [request setAccount:selectedTwitterAccount];

    //Execute request
    [request performRequestWithHandler:^(NSData *responsedata, NSHTTPURLResponse *urlResponse, NSError *error){
        if(responsedata){
            if(urlResponse.statusCode >= 200 && urlResponse.statusCode < 300){
                NSError *jsonError;
                NSDictionary *timelineData = [NSJSONSerialization JSONObjectWithData:responsedata options:NSJSONReadingAllowFragments error:&jsonError];
                if(timelineData){
                    NSLog(@"Timeline Response: %@\n", timelineData);
                }
                else {
                    //Json deserialization went wrong
                    NSLog(@"JSON error: %@ : %s", [jsonError localizedDescription], __PRETTY_FUNCTION__);
                }
            }
            else {
                //Server did not respond
                NSLog(@"The response status code is %d", urlResponse.statusCode);
            }
        }
    }];
}
jgvb
  • 304
  • 5
  • 16
  • can you update the code showing where you are requesting access to the account using `requestAccessToAccountsWithType:options:completion:` ? – quellish Aug 29 '14 at 20:11
  • can you tell me , what exactly you want timeline data or user twitter profile image? – Pawan Rai Aug 31 '14 at 18:11

1 Answers1

0

You can use this project for this purpose

https://github.com/fhsjaagshs/FHSTwitterEngine

There are two methods

// users/profile_image

- (id)getProfileImageForUsername:(NSString *)username andSize:(FHSTwitterEngineImageSize)size;

- (id)getProfileImageURLStringForUsername:(NSString *)username andSize:FHSTwitterEngineImageSize)size;

you get your profile image by this method just pass your username here

Akshit Zaveri
  • 4,166
  • 6
  • 30
  • 59
BHASKAR
  • 1,201
  • 1
  • 9
  • 20