XMPPFramework - How to get currently logged-in user's display name - ios

In my application utilizing XMPPFramework, I have a login page to authenticate one user.
Once logged in, I wish to show the displayName of the user in my status page. The displayName is a NSString in XMPPUserCoreDataStorageObject.
The following line returns me the XMPPJID of my currently logged-in user. I thought this would be useful to check against my roster to get his displayName.
[[[self appDelegate] xmppStream] myJID];
However, placing the above in the code below returns me a null.
XMPPUserCoreDataStorageObject *user = [[[self appDelegate] xmppRosterStorage]
userForJID:[[[self appDelegate] xmppStream] myJID]
xmppStream:[[self appDelegate] xmppStream]
managedObjectContext:[[self appDelegate] managedObjectContext_roster]];
Appreciate any advice on how to go about retrieving the displayName of the current user.

As vitalyster mentioned in the comment above, there is no way to retrieve my own display name if I am logged in.
To verify that, I went to my Openfire server settings.
In Users/Groups > User Summary > KeithOYS > Roster, there is no same user called KeithOYS in the roster list.
Same concept applies for every other users.
In a nutshell, every user has all other users in their Roster (as long as they are classified under the same Group), all except himself.

I have got the user name of logged in user with following code.
XMPPJID *myjid = [[[self appDelegate]xmppStream]myJID];
NSString *userName = [NSString stringWithFormat:#"%#",myjid.user];
Hope it will help someone.

Related

Missing e-mail when using ParseUI with Facebook login/signup

I'm using the the PFLogInViewController of the ParseUI framework. I have two questions related to emails with regards to Facebook Login within the framework:
1) When signing up via Facebook, I see that the email field of my new user is 'undefined.' How can I obtain the user's email address?
2) If I am able to obtain the email address, does parse's application setting of 'emailVerified' still send a verification email to the user upon Facebook signup? If not, how can this be done?
Thanks.
In order to read the user's email address you'll need to add email to your array of Facebook permissions you're requesting. Look at the Parse tutorial on this https://www.parse.com/tutorials/login-and-signup-views#properties
In your case, you'll want to add #"email" like this:
[logInViewController setFacebookPermissions:[NSArray arrayWithObjects:#"friends_about_me", #"email", nil]];
Then when you are requesting the user information from Facebook, you will be able to access the user's email address:
FBRequest *request = [FBRequest requestForMe];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Now you can access user's email
NSString *email = result[#"email"];
if (email) {
// Save it to your email field in Parse
}
}
}];
Regarding part 2 of your question, I'm not as familiar with the email validation functionality that Parse supports, but looking at this (admittedly old) response https://www.parse.com/questions/email-verification-emails-going-out-to-facebook-users it appears that Parse will validate email addresses even when the user logs in with Facebook.

Use post request to receive LinkedIn user profile information in iOS

I am looking for a way to retrieve the profile information of a LinkedIn user by making a post request, I have read these two LinkedIn pages but it doesn't seem to explain much, or I couldn't understand much of it:
REST API LinkedIn
basic profile informations
I have seen these example on stackoverflow but I didn't understood to much:
http://api.linkedin.com/v1/people/~:(id,first-name,last-name,maiden-name,email-address,formatted-name,phonetic-last-name,location:(country:(code)),industry,distance,current-status,current-share,network,skills,phone-numbers,date-of-birth,main-address,positions:(title),educations:(school-name,field-of-study,start-date,end-date,degree,activities))
I am only interested to retrieve the skills section the one that on the website appears as so:
There's a fantastic library for LinkedIn-iOS integration by Kirsten Jones, you can use that to make calls to the LinkedIn API. You need an access token to make calls.
https://github.com/PrincessPolymath/LinkedIn-OAuth-Sample-Client
Make calls like this:
NSURL *url = [NSURL URLWithString:#"http://api.linkedin.com/v1/people/~:(id,first-name,last-name,maiden-name,formatted-name,phonetic-last-name,location:(country:(code)),industry,distance,current-status,current-share,network,skills,phone-numbers,date-of-birth,main-address,positions:(title),educations:(school-name,field-of-study,start-date,end-date,degree,activities))"]];
OAMutableURLRequest *request =
[[OAMutableURLRequest alloc] initWithURL:url
consumer:oAuthLoginView.consumer
token:oAuthLoginView.accessToken
callback:nil
signatureProvider:nil];
[request setValue:#"json" forHTTPHeaderField:#"x-li-format"];
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:#selector(profileApiCallResult:didFinish:)
didFailSelector:#selector(profileApiCallResult:didFail:)];
- (void)profileApiCallResult:(OAServiceTicket *)ticket didFinish:(NSData *)data
{
NSString *responseBody = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
NSDictionary *profile = [responseBody objectFromJSONString];
if ( profile )
{
name.text = [[NSString alloc] initWithFormat:#"%# %#",
[profile objectForKey:#"firstName"], [profile objectForKey:#"lastName"]];
headline.text = [profile objectForKey:#"headline"];
.....and get skills and other user details
}
}
Use tool:https://apigee.com/console/linkedin
API to get the list of Skills:
https://api.linkedin.com/v1/people/~:(id,num-connections,skills)?format=json
I tried it in the Console tool and able to fetch the skills for my profile. I think the individual skill ID with above request should help you to get further information. Try it out.
If anyone is reading this answer, the LinkedIn API has limited access as of May 2015. You will need to apply to their Apply with LinkedIn program to access full profile fields including skills.
https://developer.linkedin.com/docs/fields
I have fair amount of experience working with the linkedIn API. It's been a little while, but hopefully this will set you on the right track.
To get profile information from a linked in user who is one of your connections you need a format like follows:
NSString *theRequest = [NSString stringWithFormat:#"https://api.linkedin.com/v1/people/id=abc123:(first-name,last-name,picture-url,location:(name))?oauth2_access_token=%#&format=json", accessToken];
This request will return the first name, last name, profile picture url, and location of the user with the id specified.
You can see a list of field types you can request by checking out linkedIn's documentation on their profile field descriptions here:
https://developer.linkedin.com/docs/fields
If you're wondering how to get the id of the user whose profile information you want request in the first place, you can make request for some basic info (including ids) of all your connections like this:
NSString *basicConnectionInfo = [NSString stringWithFormat:#"https://api.linkedin.com/v1/people/~/connections:(id,first-name,last-name)?oauth2_access_token=%#&format=json", accessToken];
This request will give you the id, first name, and last name of all of your connections. After you've gotten the id of the person you want, you can make a request using the user's id (as shown in the first example).
Now for the slightly unfortunately news... If you followed the link provided above, you'll notice that the skills field is part of the "Member profile fields available to Apply with LinkedIn developers". I'm assuming you'll have to follow this link they provided: https://developer.linkedin.com/docs/apply-with-linkedin in order to access the skills member profile field.
I have not applied with LinkedIn. So, I haven't tested a call to the skills field. But, I'm guessing it'll be similar to the examples I've shown you. Hope this helps!

Cant get FBGraphUser email

I use Facebook login with my app. (Facebook iOS SDK version 3.11.1)
I ask for "email" permission:
NSArray *permissions = [NSArray arrayWithObjects: #"basic_info", #"email", nil];
Most of the time, I do get the user's email like that:
NSString *email = [user objectForKey:#"email"];
//user is (NSDictionary<FBGraphUser> *)
Sometimes I just don't. (I can see that the NSDictionary is not including email).
I am using this fix so the app won't terminate when i use email later and its nil:
NSString *email = [user objectForKey:#"email"] ? [user objectForKey:#"email"] : #"NO_EMAIL";
But i need the real mail, so i have to come up with a new solution.
I haven't noticed something special with the problematic users.
Any ideas what can be the problem?
It appears that its a well known problem... For many reasons, not everyone on Facebook have Email address registered.
But as i said, my problem is that i need a real mail.
So the simplest solution is to use the user's Facebook Email : user_name#facebook.com
NSString *email = [user objectForKey:#"email"] ? [user objectForKey:#"email"] : [NSString stringWithFormat:#"%##facebook.com", user.username];
some links ref to that you can't sent HTML emails to the Facebook mail, only plain text!
Here is how i have done it and it always works great for me in every situation:
(I suppose that you have added email permission in your code)
Step 1
Open Facebook Framework folder in Xcode and find the FBGraphUser.h class
As you see, you have there all the properties that you use from Facebook Framework, to take the user details, so add an other property there (copy and paste the code below):
Step 2
#property (retain, nonatomic) id<FBGraphUser> email;
And you are good to go!
You could check for a couple of things:
Make sure you are requesting email scope permission in the login request dialog:
https://www.facebook.com/dialog/oauth?client_id=APP&redirect_uri=REDIRECT&state=UNIQUE&scope=email
Check if the access token you got actually has email permission granted with the Access Token Debugger.
All facebook accounts which are verified through Phone Number instead of email will get NULL for [user objectForKey:#"email"]
Facebook won't return the email address if it's not verified.
https://developers.facebook.com/docs/graph-api/reference/v2.2/user
This person's primary email address listed on their profile. This field will not be returned if no valid email address is available.

XMPPFramework - Retrieve name associated with a JID

In Openfire users are created with a "Username" (which is used as the basis for the JID) and a descriptive "Name". How does one retrieve the Name for a given JID in XMPP? I'm using XMPPFramework.
You may retrieve a user's Display Name using his JID from XMPPUserCoreDataStorageObject like this:
XMPPJID *userJID = #"shakespeare";
XMPPUserCoreDataStorageObject *user = [[[self appDelegate] xmppRosterStorage]
userForJID:userJID
xmppStream:[[self appDelegate] xmppStream]
managedObjectContext:[[self appDelegate] managedObjectContext_roster]];
NSString *userDisplayName = user.displayName;
Are you using the CoreData portion of the roster when setting up the XMPPFramework? You can get the user via the JID from the storage class that is set (for example, the XMPPRosterCoreDataStorage).
From here, you can get the user stored from the roster request via the storage class such as:
[xmppStorage userForJID:jid ...]
and from here, the resulting object (XMPPUserCoreDataStorageObject) has fields for 'nickname', 'displayName', etc. Some information can also be obtained from the associated vCard for that JID.

ACAccount Facebook property username return email and sometimes the nickname

When I access to the Facebook Account using ACAccountStore to get an ACAccount object I noticed that for some profiles the ACAccount.username give me the Facebook email but for other profiles give me the nickname... How is possible that the same property contains different value ?
This drive me crazy...
Yes, it's weird for me too.
But I can get the email from properties field like below:
NSString *email = [[account valueForKey:#"properties"] objectForKey:#"ACUIDisplayUsername"];

Resources