0

I need to display the facebook and twitter profiles names in two labels

These profiles name should be getting from settings page setup

iif is there any facebook account setup in setting i have to get the user name and displaued it in my app Same thing for twitter setup also how to achieve it.

Thanks,

Check in Settings

enter image description here

![enter image description here][2]

![enter image description here][3]

iOS dev
  • 2,254
  • 6
  • 33
  • 56
  • _"I need to display the facebook and twitter profiles names in two labels"_ – sure. is that a yet phishing app? – holex Jul 15 '14 at 08:06

1 Answers1

0

Using social framework, use you get details of accounts -

ACAccountStore *accountStore = [[ACAccountStore alloc] init] ;

ACAccountType *twitterAccountType =  [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:twitterAccountType withCompletionHandler:^(BOOL granted, NSError *error)
 {
     if(granted)
     {
         NSArray *twitterAccounts = [accountStore accountsWithAccountType:twitterAccountType];
         NSLog(@"twitterAccounts %@", twitterAccounts);
     }
 }];


ACAccountType *facebookAccountType =  [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
//your app id is the key, i have used "Demo".
NSDictionary *dictFB = [NSDictionary dictionaryWithObjectsAndKeys:@"Demo", ACFacebookAppIdKey,@[@"email"],ACFacebookPermissionsKey, nil];

[accountStore requestAccessToAccountsWithType:facebookAccountType options:dictFB completion:
 ^(BOOL granted, NSError *e) {
     if (granted) {
         NSArray *facebookAccounts = [accountStore accountsWithAccountType:facebookAccountType];
         // fb accounts
         NSLog(@"facebook accounts =%@", facebookAccounts);
     } else {
         //Error
         NSLog(@"error getting permission %@",e);
     }
 }];

Similarly if there are more than 1 accounts configured, you can iterate through those and get the information.

EDIT - What are ACFacebookAppIdKey, ACFacebookPermissionsKey?

ACCOUNTS_EXTERN NSString * const ACFacebookAppIdKey NS_AVAILABLE(NA, 6_0);            // Your    Facebook App ID, as it appears on the Facebook website.
ACCOUNTS_EXTERN NSString * const ACFacebookPermissionsKey NS_AVAILABLE(NA, 6_0);      // An array of of the permissions you're requesting.
Community
  • 1
  • 1
rishi
  • 11,779
  • 4
  • 40
  • 59
  • NSArray *facebookAccounts and twitterAccounts returns empty arrAY EVEN I HAVE ACOUNT SETUP IN SETTINGS' – iOS dev Jul 15 '14 at 08:31
  • You need to request access for account as well, check updated answer. – rishi Jul 15 '14 at 09:12
  • it returns nill array for facebook only in iOS7... and returns error for permssion The Facebook server could not fulfill this access request: invalid app id – iOS dev Jul 15 '14 at 09:28
  • what ae the ACFacebookAppIdKey, ACFacebookPermissionsKey – iOS dev Jul 15 '14 at 09:31
  • You need to check the documentation as well for micro level details. Facebook server only accept real app already on App Store so you need to pass app id of any such app. – rishi Jul 15 '14 at 09:35
  • There are couple of tutorial already available on FB integration, you need to go through them as well, else you will have question on every line of code :) – rishi Jul 15 '14 at 09:37