How to fetch facebook user friends email ids in ios - ios

m using facebook graph apis in my app.
i want to fetch my fb friends email ids
in a tableview in my app
fb graph user doesn't provides any property for emails.
how can i achive this
help me
- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView {
self.userInfoTextView.hidden = NO;
// Fetch user data
[FBRequestConnection
startForMeWithCompletionHandler:^(FBRequestConnection *connection,
id<FBGraphUser> user,
NSError *error) {
if (!error) {
NSString *userInfo = #"";
// Example: typed access (name)
// - no special permissions required
userInfo = [userInfo
stringByAppendingString:
[NSString stringWithFormat:#"Name: %#\n\n",
user.name]];
// Example: typed access, (birthday)
// - requires user_birthday permission
userInfo = [userInfo
stringByAppendingString:
[NSString stringWithFormat:#"Birthday: %#\n\n",
user.birthday]];
// Example: partially typed access, to location field,
// name key (location)
// - requires user_location permission
userInfo = [userInfo
stringByAppendingString:
[NSString stringWithFormat:#"Location: %#\n\n",
user.location[#"name"]]];
// Example: access via key (locale)
// - no special permissions required
userInfo = [userInfo
stringByAppendingString:
[NSString stringWithFormat:#"Locale: %#\n\n",
user[#"locale"]]];
// Example: access via key for array (languages)
// - requires user_likes permission
if (user[#"languages"]) {
NSArray *languages = user[#"languages"];
NSMutableArray *languageNames = [[NSMutableArray alloc] init];
for (int i = 0; i < [languages count]; i++) {
languageNames[i] = languages[i][#"name"];
}
userInfo = [userInfo
stringByAppendingString:
[NSString stringWithFormat:#"Languages: %#\n\n",
languageNames]];
}
// Display the user info
self.userInfoTextView.text = userInfo;
}
}];
}

Add this line to your code. Hope it will be helpful to you.
NSLog(#"%#",[user objectForKey:#"email"]);

You cannot obtain e-mail addresses for friends through the Facebook API (with good reason - to prevent spam). You can obtain the current user's e-mail address, but only with an extended permission (more about that here).

Related

How to get Mobile Number from vCard String Objective C

I am working on Action Extension Objective C. I have successfully created Extension for share recent contact in my Extension. In that I am getting v Card String. How can I get Mobile Number from v Card String. Any help would be appreciated.
Using contactsWithData:error: class method of CNContactVCardSerialization, you can retrieve info from a vCard.
It's from Contacts.framework, available since iOS9.
For earlier version, you can use AddressBook.framework. You can read info here.
NSError *errorVCF;
NSArray *allContacts = [CNContactVCardSerialization contactsWithData:[contactStr dataUsingEncoding:NSUTF8StringEncoding] error:&errorVCF];
if (!errorVCF)
{
NSMutableString *results = [[NSMutableString alloc] init];
//NSLog(#"AllContacts: %#", allContacts);
for (CNContact *aContact in allContacts)
{
NSArray *phonesNumbers = [aContact phoneNumbers];
for (CNLabeledValue *aValue in phonesNumbers)
{
CNPhoneNumber *phoneNumber = [aValue value];
[results appendFormat:#"%# %#\n", [aValue label], [phoneNumber stringValue]];
}
}
NSLog(#"Final: %#", results);
}

how can I access friends' facebook profile picture?

I need to access friends' profile pictures to display them in my game leaderboard. Most of the links to posts I found here on stackoverflow do not exist anymore. How can I access the profile pictures in a way similar to how I accessed the scores and names in the code below.
-(void)getLeaderboardInfo
{
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:#"%llu/scores?fields=score,user", kuFBAppID] parameters:nil HTTPMethod:#"GET" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (result && !error)
{
int index = 0;
for (NSDictionary *dict in [result objectForKey:#"data"])
{
NSString *name = [[[[dict objectForKey:#"user"] objectForKey:#"name"] componentsSeparatedByString:#" "] objectAtIndex:0];
NSString *strScore = [dict objectForKey:#"score"];
// how do I get the objectforkey representing the image?
m_pLeaderboardEntries[index].pFriendName.text = [NSString stringWithFormat:#"%d. %#", index+1, name];
m_pLeaderboardEntries[index].pFriendScore.text = [NSString stringWithFormat:#"Score: %#", strScore];
// how do I add the image to my leaderboard entries?
index++;
if (index>5) {
break;
}
}
}
}];
}
The LeaderboardInstance
struct LeaderboardboardInstance
{
__unsafe_unretained UILabel *pFriendName;
__unsafe_unretained UILabel *pFriendScore;
__unsafe_unretained UIImage *profilePicture;
};
Also,
struct LeaderboardboardInstance m_pLeaderboardEntries[m_kuLeaderboardSize];
Add this to your list of fields
picture.type(large)
In the result object you should then have a dictionary called picture which contains image info including the url of the users image
Assuming you have a Facebook user logged in and the friend's Facebook ID, this is the way to go:
NSString *imageUrl = [NSString stringWithFormat:#"http://graph.facebook.com/%#/picture?type=large", friendID];
Then you can download the image using NSURLConection or whatever library you want.

How to get Facebook feeling (smilies) in your IOS App (xcode)?

I have written an IOS App to retrieve data from the Facebook account from the user's phone. I can retrieve data like Name, Profilepicture, ... (after the user logged in with his Facebook account details).
I cannot retrieve the status of the user, more specifically the feelings (smilies) posted, like: "Feeling good", "Feeling proud", ...
I have tried the following code:
self.userprofilePicture.profileID = user.objectID; // works fine
self.userUsername.text = user.first_name; // works fine
self.userEmail.text = [user objectForKey:#"email”]; // works fine
self.userStatus.text = [result objectForKey:#"status"]; // no result
I have also tried the following:
if ([user objectForKey:#"status"]) {
NSArray *temp = [user objectForKey:#"status"];
for (int i = 0; i < [temp count]; i++) {
self.userStatus.text = [NSString stringWithFormat:#“User Status: %d, %#", i, self.temp];
}
}
Is it possible to retrieve the "feelings" information from Facebook?

Can't retrieve XMPP JID from NSMutableDictionary iOS app.

When I receive XMPP Presence in the app , I am adding its contents to a NSMutableDictionary to send it across another ViewController.If I use NSLog to see the contents of this dictionary , I can see everything fine.But when I access this NSMutableDictionary from another ViewController I can't find the JID.Rest of the things are stored fine.
This is what I am doing while storing the XMPP Presence contents i e JID and Name.
- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence
{
NSString *fromUser = [[presence from]user]; //name of user
NSString *fromUserJID = [NSString stringWithFormat:#"%#",[presence from]] ;
NSLog(#"presence from user JID :- %#", fromUserJID); // This shows the JID.
[_locationDictionary setObject:fromUser forKey:#"fromUser"];
[_locationDictionary setObject:fromUserJID forKey:#"fromJID"];
NSLog(#"locationary dictionary :- %#",_locationDictionary ); // This shows name as well as JID.
// add to array
[_presenceArray addObject:_locationDictionary];
Now when I am trying to access this in another ViewController I do this:-
NSString *str=view.annotation.title; //This has the name of the user.
NSLog(#"annotation title :- %#", str);
for (NSDictionary *obj in appDelegate.presenceArray)
{
NSString *titleString = [obj objectForKey:#"fromUser"];
if ([str isEqualToString:titleString]) //for the same username I need the JID
{
NSString *jidString = [obj objectForKey:#"fromJID"];
[ dict setObject:jidString forKey:#"jid"]; //dict is NSMutableDictionary
NSLog(#"retrieved jid is :- %#", dict); // THIS IS NULL
[presence from] will give XMPPJid which is NSObject type.
XMPPJID *jid = [presence from];
Try to get Jid string this way
NSString *fromUserJID = [[presence from] full];//Will give Jid have user, resource, domain
//OR
NSString *fromUserJID = [presence fromStr]; //Only give Jid of user.

Parsing response Facebook iOS sdk

Could you help me to parse response correctly:
Parser in - (void)request:(FBRequest *) request didLoad:(id)result:
case education:{
NSArray *arrayRsult = [[result objectForKey:#"education"] objectForKey:#"school"];
for (NSDictionary *placeForResults in arrayRsult){
NSString *output = [placeForResults objectForKey:#"name"];
NSLog(#"%#", output);
}
}
break;
My request:
- (IBAction)eduacation:(id)sender {
currentApiCall = education;
FacebookInfoGetterAppDelegate *delegate = (FacebookInfoGetterAppDelegate *) [[UIApplication sharedApplication] delegate];
[[delegate facebook] requestWithGraphPath:#"me?fields=education" andDelegate:self];
}
But it returns array with nulls. Whats wrong?
first of all you need to set up rights for this - "user_education_history"
I corrected code for your parsing part because your receive dictionary with key education that consists array of your schools.
NSArray *arrayRsult = [result objectForKey:#"education"];
for (NSDictionary *placeForResults in arrayRsult){
NSString *output = [[placeForResults objectForKey:#"school"] objectForKey:#"name"];
NSLog(#"%#", output);
}
it works for me.

Resources