I want to get user’s info. After OAuth I send this request:
NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1/account/verify_credentials.json"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"Public Timeline: %@", JSON);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"error = %@", error);
NSLog(@"json = %@", JSON);}];
[operation start];
But got an error: {"error":"Could not authenticate you.","request":"\/1\/account\/verify_credentials.json"} Why I can’t get access to information even after login in?
You haven’t attached the OAuth token to the request. You’re just sending a request with that URL string.
You might to have a look AFOAuth2Client which provides a neat extension to AFNetworking for doing authorized requests on Twitter.
Alternatively, you can use the built in iOS 5+ Twitter API, I wrote an answer for another SO post that shows you how exactly to do this – and it’s super easy 🙂
If you need to implement OAuth from scratch, please see: https://github.com/bengottlieb/Twitter-OAuth-iPhone/
Good luck!