how to invite facebook friend in ios7? - iphone

am new in ios development
when i click "find your facebook friend" button then invitaion goes to this my salected friend
how can i code for this.am using facebook sdk framework.
NSLog(#"ID=%#",[_IDArray lastObject]);
NSLog(#"Event ID:%#",_eventID);
NSData *data = [_eventID dataUsingEncoding:NSUTF8StringEncoding];
id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(#"Event ID:%#",[json objectForKey:#"id"]);
NSURL *meurl = [NSURL URLWithString:[NSString stringWithFormat:#"https://graph.facebook.com/%#/invited/%#",[json objectForKey:#"id"],[_IDArray lastObject]]];
//#"https://graph.facebook.com/EVENT_ID/invited?users=USER_ID1,USER_ID2,USER_ID3"
SLRequest *merequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:meurl
parameters:nil];
merequest.account = _facebookAccount;
[merequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *meDataString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(#"Data=%#",meDataString);
}];
}
}
but i want to use facebook sdk
please help out

Facebook have shared the way to send request and invitation as:Facebook tutorial friend requests

Related

is it possible to tag a post/photo using ios social framework?

In my app I need to tag my photo/posts. Is this possible using social framework or Should I use Facebook-sdk for this?. Also can I get friends list from social framework? any help to achieve this?
Tagging a photo or post can only be done using the FacebookSDK for iOS while getting your friends list is possible using both the SocialFramework and the FacebookSDK for iOS.
You can use this code to get your friends list using the SocialFramework.
- (void)getFbFriends
{
ACAccountStore *store = [[ACAccountStore alloc] init];
ACAccountType *facebookTypeAccount = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary *options = #{
ACFacebookAppIdKey: facebookAppId,
ACFacebookPermissionsKey: #[#"email"],
ACFacebookAudienceKey: ACFacebookAudienceFriends
};
[store requestAccessToAccountsWithType:facebookTypeAccount
options:options
completion:^(BOOL granted, NSError *error){
if(granted)
{
NSArray *accounts = [store accountsWithAccountType:facebookTypeAccount];
ACAccount *facebookAccount = [accounts lastObject];
NSURL *meurl = [NSURL URLWithString:#"https://graph.facebook.com/me"];
SLRequest *merequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:meurl
parameters:nil];
merequest.account = facebookAccount;
NSURL *requestURL = [NSURL URLWithString:#"https://graph.facebook.com/me/friends"];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:requestURL parameters:#{#"fields":#"id,name,picture,first_name,last_name,gender"}];
request.account = facebookAccount;
[request performRequestWithHandler:^(NSData *data,
NSHTTPURLResponse *response,
NSError *error) {
if(!error)
{
NSDictionary *list =[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
if([list objectForKey:#"error"]!=nil)
{
// if error occured e.g. Invalid Auth etc.
}
else
{
NSMutableArray *FBFriends = [[NSMutableArray alloc] init];
[FBFriends addObject:[userInfo objectForKey:#"id"]];
NSLog(#"friends %#", list);
}
}
else
{
NSLog(#"Error");
}
}];
}
else
{
NSLog(#"Error grant access");
}
}];
}

How to use FB Graph search API in iphone application

I am new to facebook graph api. I want to search people from facebook and show that users facebook basic information in application.How can i search people using fb graph search api. Can anyone just tell me the tutorial or any useful links for this.Thanks in advance.
Downloaded latest sample Facebook Graph API for iOS search from facebook for graph api from github and it includes sample code for the same.
// Calling facebook graph API
NSURL *requestURL = [NSURL URLWithString:#"https://graph.facebook.com/me"];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodGET URL:requestURL parameters:nil];
request.account = self.facebookAccount;
[request performRequestWithHandler:^(NSData *data, NSHTTPURLResponse *response, NSError *error)
{
if(!error)
{
NSDictionary *list =[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
//Basic profile of the user will save in list variable
NSLog(#"Dictionary contains: %#", list );
fbID = [NSString stringWithFormat:#"%#", [list objectForKey:#"id"]];
//Fetching facebook ID
gender = [NSString stringWithFormat:#"%#", [list objectForKey:#"gender"]];
//Fetching gender
playerGender = [NSString stringWithFormat:#"%#", gender];
NSLog(#"Gender : %#", playerGender);
Also import Social Account and security framework

Quering Facebook notifications using Social framework in iOS 6

I've looked around the Social Framework, but it's difficult to navigate. I figured out how to get the latest #mentions on twitter, which I do like so:
NSURL *mentionsURL = [NSURL URLWithString:#"http://api.twitter.com/1.1/statuses/mentions_timeline.json"];
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[parameters setObject:#"3" forKey:#"count"];
[parameters setObject:#"0" forKey:#"include_entities"];
SLRequest *twitterInfoRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodGET
URL:mentionsURL
parameters:parameters];
[twitterInfoRequest setAccount:twitterAccount];
[twitterInfoRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
}];
I was wanting to adapt this to get the latest notifications from Facebook, but I'm unsure what to put in the URL and parameters to make this work.

How to like a facebook page/follow a twitter user using social framework in iOS 6?

Is there an easy way to like a facebook page/follow a twitter user using social framework in iOS 6?
I can post messages to the user's facebook/twitter account fine using the framework.
This is a method for following a user on twitter
-(void)followTwitter{
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
{
NSLog(#"this is the request of account ");
if (granted==YES) {
NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
if ([arrayOfAccounts count] > 0)
{
// Keep it simple, use the first account available
ACAccount *acct = [arrayOfAccounts objectAtIndex:0];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:#"FollowedUserNameHere",#"screen_name",#"TRUE",#"follow", nil];
TWRequest *request = [[TWRequest alloc] initWithURL:[NSURL URLWithString:#"https://api.twitter.com/1.1/friendships/create.json"] parameters:dictionary requestMethod:TWRequestMethodPOST];
[request setAccount:acct];
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
if ([urlResponse statusCode] == 200)
{
// The response from Twitter is in JSON format
// Move the response into a dictionary and print
NSError *error;
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&error];
NSLog(#"Twitter response: %#", dict);
}
else
NSLog(#"Twitter error, HTTP response: %i", [urlResponse statusCode]);
}];
}
}
}];
}
and follow this link for liking facebook page
http://angelolloqui.blogspot.jp/2010/11/facebook-like-button-on-ios.html
It should be noted that as of iOS 6.0 TWRequest was deprecated in favor of SLRequest from the Social framework, eg the accepted answer at: Twitter SLRequest performRequestWithHandler - Could not prepare the URL request

upload Video to Facebook using iOS6 Social Framework

I want to publish a video file to facebook. Previously I used the Facebook iOS SDK3.0 and it works. However, for iOS6 Social Framework, there is problem.
__block ACAccount * facebookAccount;
ACAccountStore* accountStore = [[ACAccountStore alloc] init];
NSDictionary *options = #{
ACFacebookAppIdKey: #"MY APP ID",
ACFacebookPermissionsKey: #[#"publish_actions", ],
#"ACFacebookAudienceKey": ACFacebookAudienceFriends
};
ACAccountType *facebookAccountType = [accountStore
accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[accountStore requestAccessToAccountsWithType:facebookAccountType options:options completion:^(BOOL granted, NSError *error) {
if (granted) {
NSArray *accounts = [accountStore
accountsWithAccountType:facebookAccountType];
facebookAccount = [accounts lastObject];
NSLog(#"access to facebook account ok %#", facebookAccount.username);
NSData *videoData = [NSData dataWithContentsOfFile:[self videoFileFullPath]];
NSLog(#"video size = %d", [videoData length]);
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
videoData, #"video.mov",
#"video/quicktime", #"contentType" ,
#"Video title", #"title",
#"Video description", #"description",nil];
NSURL *requestURL = [NSURL URLWithString:#"https://graph.facebook.com/me/videos"];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:requestURL
parameters:params];
request.account = facebookAccount;
[request performRequestWithHandler:^(NSData *data, NSHTTPURLResponse *response,NSError * error){
NSLog(#"response = %#", response);
NSLog(#"error = %#", [error localizedDescription]);
}];
} else {
NSLog(#"access to facebook is not granted");
// extra handling here if necesary
}
}];
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[NSConcreteData
_fastCharacterContents]: unrecognized selector sent to instance 0x2097ead0'
Here is my research:
First, the video data cannot be part of the parameter list, since it will render the SLRequest invalid and that is the crash you are experiencing.
The video data must go in the multi part section of the request.
Now,there is a need to associate the parameters with the multipart data and that is the tricky part. So it is necessary to use the source attribute to make that link.
Source requires a URL in a string format set it in the parameters and set the same value in the filename field in the multipart request.
That should do it.
NSURL *url = [NSURL URLWithString:#"https://graph.facebook.com/me/videos"];
NSURL *videoPathURL = [[NSURL alloc]initFileURLWithPath:videoPath isDirectory:NO];
NSData *videoData = [NSData dataWithContentsOfFile:videoPath];
NSString *status = #"One step closer.";
NSDictionary *params = #{#"title":status, #"description":status};
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:url
parameters:params];
[request addMultipartData:videoData
withName:#"source"
type:#"video/quicktime"
filename:[videoPathURL absoluteString]];
I'm working the same issue. I think your error is from ARC and NSData *videoData gets deleted before the return from performRequestWithHandler.