How to get user account information from Twitter using objective-c? - iphone

i have used oauth mechanism to let the user login via twitter in my app, on successful login it returns me the access taken, username and oauth_token_secret, i want to get the user account information from twitter like his location, date of birth, and other profile information. I have searched the Rest Api given on the twitter's official site but haven't found any such link.... so how to get the user 's account information? kindly help me.

what about this call
https://api.twitter.com/1/users/show.json?screen_name=TwitterAPI&include_entities=true

Twitter-Kit Version 3.4.0 Here is function
-(void)userVerify:(NSString *)userID{
NSString *statusesShowEndpoint = #"https://api.twitter.com/1.1/users/show.json";
NSDictionary *params = #{#"id": userID};
NSError *clientError;
// Objective-C
TWTRAPIClient *client = [[TWTRAPIClient alloc] init];
NSURLRequest *request = [client URLRequestWithMethod:#"GET" URLString:statusesShowEndpoint parameters:params error:&clientError];
if (request) {
[client
sendTwitterRequest:request
completion:^(NSURLResponse *response,
NSData *data,
NSError *connectionError) {
if (data) {
// handle the response data e.g.
NSError *jsonError;
NSDictionary *json = [NSJSONSerialization
JSONObjectWithData:data
options:0
error:&jsonError];
NSLog(#"%#",[json description]);
self.txtViewDetails.text = [json description];
}
else {
NSLog(#"Error code: %ld | Error description: %#", (long)[connectionError code], [connectionError localizedDescription]);
self.txtViewDetails.text = [NSString stringWithFormat:#"Error code: %ld | Error description: %#", (long)[connectionError code], [connectionError localizedDescription]];
}
}];
}
else {
NSLog(#"Error: %#", clientError);
}
}

Related

Objective C retrieve twitter email from JSON

TwitterKit changed the way its email gets retrieved again and now I can't figure out how to retrieve the email from JSON using the new format.
Previously I would just do this:
TWTRShareEmailViewController* shareEmailViewController =
[[TWTRShareEmailViewController alloc]
initWithCompletion:^(NSString* email2, NSError* error) {
NSLog(#"Email %#, Error: %#", email2, error);
But now they've gotten rid of the TWTRShareEmailViewController (as of version 2.0) and I have to do this:
TWTRAPIClient *client = [TWTRAPIClient clientWithCurrentUser];
NSURLRequest *request = [client URLRequestWithMethod:#"GET"
URL:#"https://api.twitter.com/1.1/account/verify_credentials.json"
parameters:#{#"include_email": #"true", #"skip_status": #"true"}
error:nil];
[client sendTwitterRequest:request completion:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
**something should go here**
}];
...but I'm not quite sure how to get the email from the json now.
Any help would be appreciated.
Ok. In the end it was pretty easy. All I had to do was convert the JSON to a string. And from there I could do whatever I wanted to it. So I did it this way:
TWTRAPIClient *client = [TWTRAPIClient clientWithCurrentUser];
NSURLRequest *request = [client URLRequestWithMethod:#"GET"
URL:#"https://api.twitter.com/1.1/account/verify_credentials.json"
parameters:#{#"include_email": #"true", #"skip_status": #"true"}
error:nil];
[client sendTwitterRequest:request completion:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSString *json = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}];
From there you could turn it to a dictionary or array or whatever you want to do with it. Phew! I really need more sleep!

Not able to fetch the gmail address book in iPhone

From last few days i am stuck as i am not able to access my gmail address book in my iPhone app.I searched a lot but didn't get any success.
Here is the link that i refereed
I checked this link also to access gmail contacts
In the above link it is given that you can access the contacts using this url
https://www.google.com/m8/feeds/contacts/userEmail/full
I am able to login using GData framework but didn't find anything to fetch gmail contacts.
I have a access token after successful login and i am calling this method after logging in successfully.
- (void)doAnAuthenticatedAPIFetch {
NSString *urlStr = #"https://www.google.com/m8/feeds/contacts/myEmailId#gmail.com/full";
NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[self.authToken authorizeRequest:request
completionHandler:^(NSError *error) {
NSString *output = nil;
if (error) {
output = [error description];
} else {
NSURLResponse *response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
if (data) {
// API fetch succeeded :Here I am getti
output = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
} else {
// fetch failed
output = [error description];
}
}
}];
}
Please guide me.
Use this URL to get gmail account address book fetching.
http://code.google.com/p/gdata-objectivec-client/wiki/GDataObjCIntroduction
And take instruction from here how to use google api.
http://johntwang.com/blog/2009/06/08/how-to-use-google-apis-with-iphone-sdk/
hope this would be work for you.

Twitter Update to API 1.1

My current code:
SLRequest *req = [SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodGET
URL:[NSURL URLWithString:#"http://api.twitter.com/1.1/statuses/user_timeline.json"]
parameters:[NSDictionary
dictionaryWithObjects:#[user]
forKeys:#[#"screen_name"]]];
[req performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if (urlResponse.statusCode == 200){
id object = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil];
completionBlock(object);
}else {
if (error == nil)
error = [API errorWithStatusCode:urlResponse.statusCode];
errorBlock(error);
}
}];
I did made a Application on dev.twitter.com but I don't know how to implement the tokens I got from Twitter. How can I update to 1.1 without the user asking for their Twitter account?
you need to authenticate your request to get the User Timeline, see this answer
this answer is using FHSTwitterEngine to authenticate the request and then create a search query, you can get the user_timeline instead of the search query.
Hope it helps you ^_^

no returns in NSJSONSerialization

Could you please forgive me for eventual mistakes i can make asking this question me it's my first one here.
After reading several topics on this website, like this one first i'll try to use the describe methods but it still doesn't work # all :-(
My .json file looks like this
{ "speakers" :
[
{
"name":"Value",
"picture": "URL VALUE",
"business":"VALUE",
"desc":"VALUE",
"twitter": "URL VALUE"
}
{
...
}
]
}
So this is my reasoning :
I firstly have a dictionary which contains speaker attribute
This one contains an array, field by some dictionnaries within "name", "business",... attr.
So, this is my obj-C code :
NSString *URLStr = #"URLofMyJsonFile";
NSURLRequest *JSONRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithString:URLStr ]]];
NSData *JSONData = [NSURLConnection sendSynchronousRequest:JSONRequest returningResponse:nil error:nil];
NSError *parsingError = nil;
NSDictionary *speakerDictionnary = [NSJSONSerialization JSONObjectWithData:JSONData options:0 error:&parsingError];
NSArray *speakersArray = [speakerDictionnary objectForKey:#"news"];
for (NSDictionary *oneSpeaker in speakersArray) {
NSLog(#"The speakers's name is %#", [oneSpeaker objectForKey:#"name"]);
NSLog(#"The speakers's business is %#", [oneSpeaker objectForKey:#"business"]);
NSLog(#"The speakers's desc is %#", [oneSpeaker objectForKey:#"desc"]);
}
EDIT : I remplace the right URL of my Script with Dummy
Your JSON isn't valid, there needs to be a comma between the individual speaker dictionaries.
{ "speakers" :
[
{
"name":"Value",
"picture": "URL VALUE",
"business":"VALUE",
"desc":"VALUE",
"twitter": "URL VALUE"
} <=== MISSING COMMA HERE
{
...
}
]
}
As omz mentioned the json is wrong. you can try below code :
[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.appios.fr/client/takeoff/app/script/jsonSpeaker.json"]] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *reponse,NSData *data,NSError *error){
if (!error) {
NSError *jsonError;
id json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&jsonError];
NSArray *speakersList = [json objectForKey:#"speakers"];
[speakersList enumerateObjectsUsingBlock:^(NSDictionary *dict,NSUInteger idx,BOOL *Stop){
NSLog(#"Name : %#",[dict objectForKey:#"name"]);
}];
}
} ];

FBConnect iphone : I coud'nt get Photos albums for some account ?

Maybe someone can't help me.
I use the last FBConnect (http://github.com/facebook/facebook-ios-sdk/) for Facebook connexion.
And I retreive the list of photos albums for the user.
NSMutableDictionary* params = [NSMutableDictionary NictionaryWithObjectsAndKeys:_facebook.accessToken,#"access_token",nil];
[_facebook requestWithGraphPath:#"me/albums" andParams:params andDelegate:self];
I'm testing with 4 differents account with all the same rules for privacy (Account/Privacy settings). And for some of them the albums list is empty ? And if i test via a webbrowser on a desktop computer (https://graph.facebook.com/me/albums) for account who doesn't work on iphone, the list is not empty ?
On iphone, i use graph api or FQL with same results ("SELECT aid FROM album WHERE owner = me()")
Maybe i miss some think about configuration off the facebookapp ?
Thanks for answer.
I resolve the solution with good settings for facebook authentifications
http://developers.facebook.com/docs/authentication/permissions
THIS WILL PUT ALL THE IMAGES OF THE ALBUM IN SOURCE ARRAY!
NSURL *url1 = [NSURL URLWithString:[NSString stringWithFormat:#"https://graph.facebook.com/%#/photos&access_token=AAACeFkezepQBANpoFq9I3Hts0JdE6Xis3UpZBqNxpgw62zWSlhSYyYcluGaaxH3IlKIh9w8OYrXYF9MsAxhk6ta1ANZClCaznpdSaERgZDZD",A_ID]];
URLWithString:#"https://graph.facebook.com/114750591966408/photos&access_token=//AAACeFkezepQBANpoFq9I3Hts0JdE6Xis3UyYcluGaaxH3IlKIh9w8OYrXYF9MsAxhk6ta1ANZClCaznpdSaERgZDZD"];
NSData *data1 = [NSData dataWithContentsOfURL:url1];
NSString *str1=[[NSString alloc] initWithData:data1 encoding:NSASCIIStringEncoding];
// NSString *str1=[[NSString alloc]ini]
NSDictionary *userData1 = [str1 JSONValue];
NSArray *arrOfimages=[userData1 objectForKey:#"data"];
NSMutableArray *sourceUrls = [[NSMutableArray alloc] initWithCapacity:0];
for(NSDictionary *subDictionary in arrOfimages)
{
[sourceUrls addObject:[subDictionary objectForKey:#"picture"]];
}
publish_actions and user_photos permissions is required.
And then please try the following code :
[FBRequestConnection startWithGraphPath:#"me/albums"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Success! Include your code to handle the results here
NSLog(#"user events: %#", result);
NSArray *feed =[result objectForKey:#"data"];
for (NSDictionary *dict in feed) {
NSLog(#"first %#",dict);
}
} else {
// An error occurred, we need to handle the error
// Check out our error handling guide: https://developers.facebook.com/docs/ios/errors/
NSLog(#"error %#", error.description);
}
}];