7

I need to be able to create user specific REST requests, e.g., selecting all a user's accounts etc. and therefore I would like to be able to capture the user's login username or identifier which I can then tie into my REST request. Does anyone have a solution for this?

7

When you log in through an API, the login response includes the current user's ID. You can use this ID value to filter queries tailored to that specific user. See the Force.com REST API Developer's Guide for details.

  • I see this message in the debug screen: 'SFAuthenticationManager|oauthCoordinatorDidAuthenticate for userId: '. Do you know is there a method I can call or edit so that I can capture the result as a variable that I can then work with. – Bartley Sep 25 '13 at 17:52
  • 1
    I'm not fluent in Objective-C, but it looks like you can subscribe an SFOAuthCoordinatorDelegate to receive the credentials, including a session id, user id, and organization id on a successful login or refresh. – sfdcfox Sep 25 '13 at 18:20
  • 1
    @interface LoginResponder : NSObject <SFOAuthCoordinatorDelegate> ... I'm learning, kind of. – sfdcfox Sep 25 '13 at 19:59
  • Hi @sfdcfox I'm an x-code/objective-c noob - I've created a class LoginResponder but I guess I have to somehow pass it the SFOAuthCoordinatorDelegate and don't know how to pass in the credentials, any help here would be great! – Bartley Oct 14 '13 at 17:21
5

I found the answer, thanks in part to a post from @Mobiral: add the following lines to the code of the .m (implementation) file of the class you want to use the info in, for example - see below, you could display the name of the current logged in user in a label on the first/home page of the app (using the ViewWIllAppear method to update the label):

#import "SFIdentityData.h"
#import "SFAccountManager.h"

...

-(void) ViewWillAppear:BOOL(animated){
NSString *username = [SFAccountManager sharedinstance].idData.username
labelUserId.text = userName
}

the label will display the username of the logged in user everytime the view appears.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.