I'm developing a small app with Xcode that logs into Facebook and retrieves user informations. This is the part of code that performs the request:
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *user,
NSError *error) {
if (!error) {
// at this point user variable contains all user's info I need
NSLog (#"%#", user.name);
} else {
NSLog(#"ERRORE");
}
}];
These infos are returned in English. How can I retrieve them in the same language of Facebook profile ? For example, since the language I choose for my Facebook profile is Italian, I need to retrieve all my infos in italian (with this code user[#"relationship_status"] returns "married", it should return "sposato")
Thanks to this post I found out (a possible) solution: run a FQL query with the locale parameter set to the desired language. In my case it should be locale=it_IT, as stated by this table
Related
I have logged in on my iOS app that I am building using the easier method of FBSDKLoginButton.
Since all I want is the users name and a link to their facebook I know I can find this under [FBSDKProfile currentprofile].
My question really is how do I use this?
I am trying all sorts of combinations but something akin to the below is an example of what I'm doing.
[FBSDKProfile enableUpdatesOnAccessTokenChange:YES];
NSString *name = [[NSString alloc]init];
name = [[FBSDKProfile currentProfile]firstName];
I figure since my app now has access which I quickly tested through an if on the [FBSDKAccessToken currentAccessToken] so I believe I am primed. My app delegate is all setup also. So shouldn't my above code just work? I mean, I assume currentProfile is set if a user is logged in? Maybe? Arghhh!!!
Thanks guys
Try this code :
FBRequestHandler completionBlock = ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
NSLog(#"USER DICTIONARY : %#", user);
};
[[FBRequest requestForMe] startWithCompletionHandler:completionBlock];
you can then get the user details from the user dictionary.
I sorted it guys. Essentially the FBSDKLoginButton logs you in but offers no permissions. Simply ask for them as so;
loginButton.readPermissions = #[#"email", #"public_profile"];
Then the normal code I tried in my above comment will work. My mistake here is I assumed a simple login would at least give me the public profile. It doesn't, you have to ask.
Is there any way that i can get friend list of any of my friends by using their user id or username??
I used FBfriendPickerDelegate to get my friend list but how can i get others friendlists by their id?
UPDATE THE ANSWER
I found a solution for it
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
NSArray* friends = [result objectForKey:#"data"];
NSLog(#"Found: %i friends", friends.count);
NSString * friendListString = #"" ;
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog (#"Friend Name %#,Friend ID %#",friend.name,friend.id);
}
Only with a valid access_token and permissions otherwise the ability to abuse this and spam people would be too great. A user must explicitly grant your app access to their friends/friendlists for you to access them
https://developers.facebook.com/docs/facebook-login/permissions/v2.0#reference-friends
Since Apr 30th's Facebook API v2.0, it's no longer possible to get any of your friends information (all user_* permission were removed).
I have used FacebookSDK.framework for Facebook integration in my application. I have to like one facebook page from application. I have used following code for liking page.
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:#"https://www.facebook.com/demoappname"
, #"object",
nil
];
/* make the API call */
[FBRequestConnection startWithGraphPath:#"me/og.likes"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
)
{
NSDictionary *currentResult= [(NSArray *)[result data] objectAtIndex:0];
if(!error)
{
NSLog(#"there is no error");
}
else
{
NSLog(#"There is something wrong at here.");
}
}];
But I am not clear what I have to pass in "object" parameter. Can anybody help to what I am doing wrong at here.
Thanks,
If you read this documentation, it says-
The og.likes action can refer to any open graph object or URL, except for Facebook Pages or Photos.
So, liking a page with Graph API isn't possible.
The only thing you can do- add a Like Button to the page in your app.
I am building an iOS application that is connected to Facebook. I got most of the Facebook related code (pretty much copied all of it) from the TokenCacheHowTo project. I have run into two problems, one which had a simple fix, but I think may be causing my second problem.
At first the login wasn't persisting. I had copied all the code from TokenCacheHowTo, so I was confused why and looked for a solution. Eventually I found this question and it said that if I removed #[#"basic_info"] from the permissions parameter it would work. And it did. I am still confused as to why it would work. Note: I removed #[#"basic_info"] from the openSessionWithAllowLoginUI method in my app delegate.
My problem now is that I want a list of the users friends, so I do the following request in the app delegate.
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
NSLog(#"Under");
NSArray* friends = [result objectForKey:#"data"];
NSLog(#"Found: %i friends", friends.count);
}];
This code outputs Found: 0 friends within my app delegate, but if I put the code in the same place in TokenCacheHowTo it outputs Found: X friends where X is my actual number of friends. This is confusing to me because I am able to get the users information such as their id and name from Facebook and store it on my server.
I realize that there is probably a simple solution to this but I don't have a good grasp of the Facebook SDK yet and I'm stuck.
Try this as working fine for me and Ensure about the Permissions like
NSArray *array = [NSArray arrayWithObjects:#"user_friends", nil];
and then fetch all the friend
-(void)getFriendList {
FBRequest* friendsRequest = [FBRequest requestWithGraphPath:#"me?fields=friends.fields(first_name,last_name)" parameters:nil HTTPMethod:#"GET"];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
NSDictionary* friendsDic = [result objectForKey:#"friends"];
NSArray *friends = [friendsDic objectForKey:#"data"];
for (NSDictionary *friend in friends) {
NSLog(#"firstname %#",friend[#"first_name"]);
NSLog(#"last name %#",friend[#"last_name"]);
}
}];
}
Nothing wrong with your code. I've used the same code which you used above and I got x friends list. But my permission is declared as below
FBSession.activeSession = [[FBSession alloc] initWithPermissions:[NSArray arrayWithObjects:#"user_about_me", #"email",#"user_birthday", nil]];
Note: I want email id and birthday from users that why my permissions include that fields. And It should be declared before authentication, then only sessions kept this permission as it is.
I am beginner in ObjectiveC programming language.
I developing application, using Facebook.
I try to fetch Hometown name.
Now, i want copy "Sveti Martin na Muri" to string to display in tableview.
I use:
FBRequest *friendRequest = [FBRequest requestForMe];
[friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error)
and output is:
NSLog(#"%#", [result objectForKey:#"hometown"]);
{
id = 107836872573218;
name = "Sveti Martin na Muri";
}
The same problem i have with relationship, work, location and education.
How can I access only name?
Sorry for my bad English.
greetings from Croatia.
The following code:
[result objectForKey:#"hometown"]
returns a NSDictionary with two field id and name.
You can access the name like:
NSLog(#"%#", [[result objectForKey:#"hometown"] objectForKey:#"name"]);