app id in slrequest - iphone

Is it mandatory to use app Id while integrating with Facebook using SLRequest actually I don't have the App id,so is it possible to integrate Facebook using SLRequest without using app id as i dont have a registered itunes account?
-(void)viewDidLoad
{
self.accountStore = [[ACAccountStore alloc]init];
ACAccountType *FBaccountType= [self.accountStore accountTypeWithAccountTypeIdentifier:
ACAccountTypeIdentifierFacebook];
NSString *key = #"987654";
NSDictionary *dictFB = //use ACAccountStore to help create your dictionary
[self.accountStore requestAccessToAccountsWithType:FBaccountType options:dictFB
completion: ^(BOOL granted, NSError *e) {
if (granted) {
NSArray *accounts = [self.accountStore accountsWithAccountType:FBaccountType];
//it will always be the last object with SSO
self.facebookAccount = [accounts lastObject];
}
else {
//Fail gracefully...
NSLog(#"error getting permission %#",e);
}
}];

Here the appId means the Facebook Client Id. In Facebook developer account , you will get the App ID/API Key, where you would have created your application.

Related

What should I write in place of ACFacebookAppIdKey?

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *facebookAcc = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary *options = #{ (NSString *)ACFacebookAppIdKey: #"##########",
(NSString *)ACFacebookPermissionsKey: [NSArray arrayWithObject:#"email"],
(NSString *)ACFacebookAudienceKey: ACFacebookAudienceEveryone,
};
[accountStore requestAccessToAccountsWithType:facebookAcc options:options completion:^(BOOL granted, NSError *error){
if (granted) {
ACAccount *facebookAccount = [[accountStore accountsWithAccountType:facebookAcc] firstObject];
NSLog(#"facebook usre name: %#, Full name: %#", facebookAccount.username, facebookAccount);
}
else if (error)
NSLog(#"Error occured:%#", [error localizedDescription]);
}];
}
and I am getting
Error occurred:The Facebook server could not fulfill this access request: invalid app id
what should I write ACFacebookAppIdKey
go to https://developers.facebook.com/. Create new a new app for iOS or choose your app. At the Dashboard menu, you can see your App ID. This App ID you should put to the ACFacebookAppIdKey.

How to do Facebook login in iOS >= 6 without Facebook sdk

How to do Facebook login in iOS without Facebook sdk(i am supporting iOS6 and iOS7).
My app is using Facebook login and user can share post on Facebook. Also i need to send the Facebook user id and auth token to my server.
Earlier I was supporting iOS 5 but now my iOS target >= iOS6 with Xcode 5.
For this i used Facebook SDK 3.11. From researching, i come to know that we can use SLComposeViewController, UIActivityViewController or SLRequest to share post. This will solve my sharing issue but how to do Facebook login and get auth token?
I tried SLRequest for Facebook login and SLComposeViewController for sharing, then is this good solution? (Here, i want to show Facebook native share dialog. So i haven't use SLRequest to share post because we have to make view for it.)
I referred this link. Is this the best solution to go forward?
only
-if you have deployment target 6
-you have set your bundle id in setting, develelopers.facebook.com
-you have set fb_app_id in your plist then
do like this without facebook sdk,
#import <Social/Social.h>
#import <Accounts/Accounts.h>
#define FB_APP_ID #"45666675444" // ur id here
#interface OGShareViewController ()
#property (strong, nonatomic) ACAccountStore *accountStore;
#property (strong, nonatomic) ACAccount *facebookAccount;
#property (strong, nonatomic) ACAccountType *facebookAccountType;
#end
-(void)viewDidLoad
{
[self getMyDetails];
}
- (void) getMyDetails {
if (! _accountStore) {
_accountStore = [[ACAccountStore alloc] init];
}
if (! _facebookAccountType) {
_facebookAccountType = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
}
NSDictionary *options = #{ ACFacebookAppIdKey: FB_APP_ID };
[_accountStore requestAccessToAccountsWithType: _facebookAccountType
options: options
completion: ^(BOOL granted, NSError *error) {
if (granted) {
NSArray *accounts = [_accountStore accountsWithAccountType:_facebookAccountType];
_facebookAccount = [accounts lastObject];
NSURL *url = [NSURL URLWithString:#"https://graph.facebook.com/me"];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:url
parameters:nil];
request.account = _facebookAccount;
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:responseData
options:NSJSONReadingMutableContainers
error:nil];
NSLog(#"id: %#", responseDictionary[#"id"]);
NSLog(#"first_name: %#", responseDictionary[#"first_name"]);
NSLog(#"last_name: %#", responseDictionary[#"last_name"]);
NSLog(#"gender: %#", responseDictionary[#"gender"]);
NSLog(#"city: %#", responseDictionary[#"location"][#"name"]);
NSLog(#"user name: %#", responseDictionary[#"username"]);
// http://graph.facebook.com/facebook/picture?type=normal
NSString *userPic = [NSString stringWithFormat:#" http://graph.facebook.com/%#/picture?type=normal", responseDictionary[#"username"]
];
NSLog(#"profile pic link: %#", userPic);
}];
} else {
[self showAlert:#"Facebook access for this app has been denied. Please edit Facebook permissions in Settings."];
}
}];
}
- (void) showAlert:(NSString*) msg {
dispatch_async(dispatch_get_main_queue(), ^(void) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"WARNING"
message:msg
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
});
}

Get Facebook uid from ACAccountStore in iOS?

Hi i want to get the Facebook user's UID from ACAccountStore in iOS 6
self.accountStore = [[ACAccountStore alloc]init];
ACAccountType *FBaccountType= [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSString *key = #"01234567890123";
NSDictionary *dictFB = [NSDictionary dictionaryWithObjectsAndKeys:key,ACFacebookAppIdKey,#[#"email"],ACFacebookPermissionsKey, nil];
[self.accountStore requestAccessToAccountsWithType:FBaccountType options:dictFB completion:
^(BOOL granted, NSError *e) {
if (granted) {
NSArray *accounts = [self.accountStore accountsWithAccountType:FBaccountType];
//it will always be the last object with single sign on
self.facebookAccount = [accounts lastObject];
//i Want to get the Facebook UID and log it here
NSLog(#"facebook account =%#",self.facebookAccount);
} else {
//Fail gracefully...
NSLog(#"error getting permission %#",e);
}
}];
self.facebookAccount has UID, but i am unable to get it...
I wanted to get the UID without using the Facebook API. It can done by using the following method
self.accountStore = [[ACAccountStore alloc]init];
ACAccountType *FBaccountType= [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSString *key = #"01234567890123";
NSDictionary *dictFB = [NSDictionary dictionaryWithObjectsAndKeys:key,ACFacebookAppIdKey,#[#"email"],ACFacebookPermissionsKey, nil];
[self.accountStore requestAccessToAccountsWithType:FBaccountType options:dictFB completion:
^(BOOL granted, NSError *e) {
if (granted) {
NSArray *accounts = [self.accountStore accountsWithAccountType:FBaccountType];
//it will always be the last object with single sign on
self.facebookAccount = [accounts lastObject];
//i got the Facebook UID and logged it here (ANSWER)
NSLog(#"facebook account =%#",[self.facebookAccount valueForKeyPath:#"properties.uid"]);
} else {
//Fail gracefully...
NSLog(#"error getting permission %#",e);
}
}];
You need to call the Facebook Graph API; use the SLRequest as follows:
NSUrl requestURL = NSUrl.FromString("https://graph.facebook.com/me");
SLRequest sl = SLRequest.Create(SLServiceKind.Facebook, SLRequestMethod.Get, requestURL, null);
sl.Account = // your ACAccount object here
sl.PerformRequest((data, response, error) => {
if (error == null) {
// success! parse response
}
else {
// handle failure
}
});
That should do it!

Get Twitter Profile Pic iPhone iOS5

I need help getting the twitter profile pic once I've been granted access to the Twitter account. The code below gets me the profile handle (#twitter). Is there a way to pull this info directly from Twitter in iOS5?
Here's what I have that works for the handle:
-(void)getTwitterName
{
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
{
if(granted) {
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
}
}
You can get it from this URL: http://api.twitter.com/1/users/profile_image/:screen_name.format
My profile image, for example, would be http://api.twitter.com/1/users/profile_image/don_kim
You can read more on it here.

Retain UserName in Twitter iOS5 iPhone

I want to hit add a button that allows the user to sign into their twitter account in iOS 5, but I want their twitter handle to populate into a UITextField. I have code to make sure their iPhone is running iOS 5 and their account is enabled. How do I retain their handle?
//get Twitter username and store it
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted) {
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
;
[[NSUserDefaults standardUserDefaults] setValue:twitterAccount.username forKey:#"twitterHandle"];
}
//get the username later...
[textField setText:[[NSUserDefaults standardUserDefaults] valueForKey:#"twitterHandle"]];
You can get their handle out of the ACAccount object and save it in a default or elsewhere.
http://developer.apple.com/library/ios/DOCUMENTATION/Accounts/Reference/ACAccountClassRef/Reference/Reference.html#//apple_ref/doc/uid/TP40011019-CH1-DontLinkElementID_5