How to use FB Graph search API in iphone application - iphone

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

Related

how to invite facebook friend in ios7?

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

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

How to check that user has allowed my app to post on facebook wall or not after login with facebook?

I am facing a problem regarding facebook sdk in ios . I made an app that uses facebook login and at the time of login it ask me to allow permission that my app can post on my facebook wall or not. I want to check that permission is allowed by the user or not. How can I check that. Do you have any idea?
Thank you!
Try it :
NSString *theWholeUrl = [NSString stringWithFormat:#"https://graph.facebook.com/me/permissions?access_token=%#",[[FBSession activeSession] accessToken]];
NSLog(#"TheWholeUrl: %#", theWholeUrl);
NSURL *facebookUrl = [NSURL URLWithString:theWholeUrl];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:facebookUrl];
[req setHTTPMethod:#"GET"];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&err];
NSString *content = [NSString stringWithUTF8String:[responseData bytes]];
//NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
SBJSON *json = [SBJSON new];
NSError *error = nil;
NSDictionary * dictionary =[json objectWithString:content error:&error];
The accepted answer uses the Graph API but I presume you are using the native iOS Facebook SDK to make things easier?
If so you can find your issue fully documented by Facebook here. They cover all the different scenarios, including how to handle declined permissions and how to re-ask for permission when you need it.
The right way to do this with the Graph API is to use User.permissions.
https://developers.facebook.com/tools/explorer/?method=GET&path=me%2Fpermissions

How to Upload Photos on facebook using Graph API in iPhone?

I have made one application, In my application I have integrate Facebook for sharing information.
for Facebook integration I have use Graph API in application.
now In my application, I want to upload photo on user's wall.
I have use this code for upload photo on user's wall.
// for upload photo
- (void)uploadPhoto:(id)sender {
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"Image1" ofType:#"jpg"];
NSString *message = [NSString stringWithFormat:#"I think this is a Great Image!"];
NSURL *url = [NSURL URLWithString:#"https://graph.facebook.com/me/photos"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request addFile:filePath forKey:#"file"];
[request setPostValue:message forKey:#"message"];
[request setPostValue:_accessToken forKey:#"access_token"];
[request setDidFinishSelector:#selector(sendToPhotosFinished:)];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)sendToPhotosFinished:(ASIHTTPRequest *)request {
// Use when fetching text data
NSString *responseString = [request responseString];
NSMutableDictionary *responseJSON = [responseString JSONValue];
NSString *photoId = [responseJSON objectForKey:#"id"];
NSLog(#"Photo id is: %#", photoId);
NSString *urlString = [NSString stringWithFormat:
#"https://graph.facebook.com/%#?access_token=%#", photoId,
[_accessToken stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURL *url = [NSURL URLWithString:urlString];
ASIHTTPRequest *newRequest = [ASIHTTPRequest requestWithURL:url];
[newRequest setDidFinishSelector:#selector(getFacebookPhotoFinished:)];
[newRequest setDelegate:self];
[newRequest startAsynchronous];
}
But, here I get
responseString is {"error":{"message":"Error validating application.","type":"OAuthException"}} and
Photo id is: (null)
and Image is not upload on user's wall.
so, please tell me how to solve it.
First have you authorized your application to upload pictures by doing this (using the FBConnect SDK), you can checkout all permissions here
NSArray* permissions = [NSArray arrayWithObjects:#"publish_stream", #"user_photos", nil];
[facebook authorize:permissions];
The next problem is that facebook does not allow posts sent in this way to link to pictures hosted on their domains (I know it's REALLY annoying, maybe it would be worth checking if things have changed since april). I spent quite a bit of time working this one out. The way I cracked it was to create a redirect URL using bitly (you can access their services programatically using their API, there's an obj-c wrapper for it here, although I changed it to be asynchronous) and send that URL in the post.
may help u
//facebook post a image on wall
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
userImgView.image, #"picture",
nil];
[facebook requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
another way is bellow for post image on Facebook ...
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:2];
//create a UIImage (you could use the picture album or camera too)
UIImage *picture = [UIImage imageNamed:"yourImageName"];
//create a FbGraphFile object insance and set the picture we wish to publish on it
FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:picture];
//finally, set the FbGraphFileobject onto our variables dictionary....
[variables setObject:graph_file forKey:#"file"];
[variables setObject:#"write your Message Here" forKey:#"message"];
//the fbGraph object is smart enough to recognize the binary image data inside the FbGraphFile
//object and treat that is such.....
//FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:#"117795728310/photos" withPostVars:variables];
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:#"me/photos" withPostVars:variables];
hope , this help you...
:)
The facebook API uses OAuth to authenticate requests. You will need to use a library that can request the appropriate temporary/client tokens, and generate the appropriate HTTP headers for requests. This is quite a complicated procedure which involves hashing and normalizing of request arguments.
You cannot do this crafting your own manual HTTP requests .
You can use facebook's native function
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys: UIImageJPEGRepresentation(postImage, 1.0), #"source", self.postTextView.text, #"message", nil];
/* make the API call */
[FBRequestConnection startWithGraphPath:#"/me/photos" parameters:params HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
if (error == nil) {
NSLog("Success");
}
else {
NSLog("Failed");
}
}];
Using this code you can post image with message.
Best regards