I am trying to search places from the GraphAPI using following code without luck. Can anybody please enlight my path ?
If I try to post link/message/photo it works as expected but when trying to get location it always fails and gives me **The operation couldn’t be completed. (facebookErrDomain error 10000.)**
//Following statement is using permissions
NSArray * permissions = [NSArray arrayWithObjects:#"publish_stream",#"user_checkins", #"friends_checkins", #"publish_checkins", nil];
[facebook authorize:FB_APP_ID permissions:permissions delegate:_delegate];
NSString *centerString = [NSString stringWithFormat: #"%f,%f", 37.76,-122.427];
NSString *graphPath = #"search";
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"coffee",#"q",
#"place",#"type",
centerString,#"center",
#"1000",#"distance", // In Meters (1000m = 0.62mi)
nil];
[facebook requestWithGraphPath:_path andParams:_params andHttpMethod:#"POST" andDelegate:_delegate];
Never mind. Downloaded latest sample HackBook from facebook for graph api from github and it includes sample code for the same.
For "search" you should use "GET" instead of "POST".
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#search
With Facebook iOS SDK, you can use FBRequestConnection after login.
[FBRequestConnection startWithGraphPath:#"search?q=coffee&type=place¢er=37.76,-122.427&distance=1000"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Sucess! Include your code to handle the results here
NSLog(#"result: %#", result);
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"error: %#", error);
}
}];
With Last SDK
NSMutableDictionary *params2 = [NSMutableDictionary dictionaryWithCapacity:3L];
[params2 setObject:#"37.416382,-122.152659" forKey:#"center"];
[params2 setObject:#"place" forKey:#"type"];
[params2 setObject:#"1000" forKey:#"distance"];
[[[FBSDKGraphRequest alloc] initWithGraphPath:#"/search" parameters:params2 HTTPMethod:#"GET"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
NSLog(#"RESPONSE!!! /search");
NSLog(#"result %#",result);
NSLog(#"error %#",error);
}];
Related
I am using PARSE integration for facebook. I am able to successfully link the user to facebook but when i try to get facebook firiends list i get the following error.
FBRequest *request = [FBRequest requestForMyFriends];
// Send request to Facebook
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
}];
error code = 100
message = "(#100) Unknown fields: username."
type = OAuthException
desperately need help!!
The field username is no longer available with the Graph API v2.0, see https://developers.facebook.com/docs/apps/changelog#v2_0_graph_api
Endpoints no longer available in v2.0:
...
/me/username is no longer available.
-(IBAction)btnFacebookClick:(id)sender
{
NSArray *permissions = [[NSArray alloc] initWithObjects: #"user_about_me,user_birthday,user_hometown,user_location,email",#"read_mailbox",#"read_stream",nil];
[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES completionHandler:^(FBSession *session,FBSessionState status,NSError *error)
{
if(error)
{
NSLog(#"session error %#",error);
}
else if(FB_ISSESSIONOPENWITHSTATE(status))
{
[self getFriendList];
}
}];
}
-(void)getFriendList
{
FBRequest *friendsRequest=[FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler:^(FBRequestConnection *connection,NSDictionary* result,NSError *error)
{
friendsArr = [result objectForKey:#"data"];
NSLog(#"friends description :%#",[friendsArr description]);
}];
}
I have the following code:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:txtComment.text, #"message", nil];
NSString *strPicId = [[Appdel.arrFacebookImages objectAtIndex:Appdel.getIndex] valueForKey:#"id"];
NSString *strPath =[NSString stringWithFormat:#"%#/comments",strPicId];
[FBRequestConnection startWithGraphPath:strPath parameters:params HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result1, NSError *error)
{
if(!error)
{
}
else
{
NSLog(#"ERROR:%#",error);
}
}];
but when it runs, it giving me error like below,
ERROR:Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0xb36dd80 {com.facebook.sdk:HTTPStatusCode=403, com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 200;
message = "(#200) Requires extended permission: publish_stream";
type = OAuthException;
};
};
I have successfully logged in and I am also getting photo albums, photos, comments, but I can't post any comment on any photo.
It looks like you are missing publish permission in your access token.
You can get it with:
[FBSession openActiveSessionWithPublishPermissions:#[#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
if (FBSession.activeSession.isOpen && !error) {
// Publish the comment (your code inside) if permission was granted
[self publishComment];
}
}];
That was the code from: https://developers.facebook.com/docs/ios/publish-to-feed-ios-sdk/
I want to get in my app info about the user. His name, age, location, gender, profile image and other stuff.
For now i am using :
-(void)facebookOpenSession{
FBRequest *me = [FBRequest requestForMe];
[me startWithCompletionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
NSDictionary *resultDic = (NSDictionary<FBGraphUser> *) result;
facebookData = [[NSMutableDictionary alloc]initWithDictionary:resultDic];
FBRequest *pic = [FBRequest requestForGraphPath:#"me/?fields=picture"];
[pic startWithCompletionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
NSDictionary *resultDic = (NSDictionary<FBGraphUser> *) result;
NSDictionary *dic = [resultDic objectForKey:#"picture"];
NSDictionary *dic2 = [dic objectForKey:#"data"];
NSString *imgUrl = [dic2 objectForKey:#"url"];
NSLog(imgUrl);
}];
}];
}
I made two requests ine for the user profile and one other for the image, and i want to know if i can make only one call? and if i want to get another info what i need to do?
The way you annotated your code is a little weird to read for me, so I re-wrote it like so:
if (FBSession.activeSession.isOpen) {
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {
self.nameString = user.name;
self.profileImage.profileID = user.id;
self.userName = user.username;
}
}];
}
It really isn't much more complicated than how I wrote it.
Happy Coding!
Addition to code due to comments:
You need to get the output from Facebook. For an image, your code should look like:
FBProfilePictureView *profileImage.profileID = user.id;
user.id comes from Facebook once you initiate an FBRequest.
You don't really convert the FBProfilePictureView into a UIImageView, but instead, set the FBProfilePictureView as a subview of a UIView that you create.
Also, you need to set the picture cropping:
profileImage.pictureCropping = FBProfilePictureCroppingSquare;
FBProfilePictureCroppingSquare is one of a few choices that you have. Read up on the documentation in Facebook Developer to see your options.
I am trying to post a message on my wall and wanted to tag multiple users at a time in this post. I tried the various options on the FB post page but couldn't do it. May be I am not doing it right. Any help is appreciated and this is how I am doing it...
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Test 2",#"message",
#"100004311843201,1039844409", #"to",
nil];
[self.appDelegate.facebook requestWithGraphPath:#"me/feed" andParams:params andHttpMethod:#"POST" andDelegate:self];
I have also tried message_tags but that doesn't seem to work as well.
You would need to use Open Graph to tag people with a message. The me/feed Graph API endpoint doesn't support this.
Mentions Tagging
https://developers.facebook.com/docs/technical-guides/opengraph/mention-tagging/
Action Tagging:
https://developers.facebook.com/docs/technical-guides/opengraph/publish-action/
You can take a look at the Scrumptious sample app that comes included with the latest Facebook SDK for iOS to see how to do this.
To tag a friend in ur fb status ..you need "facebook id" of your friend by using FBFriendPickerViewController and "place id" using FBPlacePickerViewController. Following code will help you.
NSString *apiPath = nil;
apiPath = #"me/feed";
if(![self.selectedPlaceID isEqualToString:#""]) {
[params setObject:_selectedPlaceID forKey:#"place"];
}
NSString *tag = nil;
if(mSelectedFriends != nil){
for (NSDictionary *user in mSelectedFriends) {
tag = [[NSString alloc] initWithFormat:#"%#",[user objectForKey:#"id"] ];
[tags addObject:tag];
}
NSString *friendIdsSeparation=[tags componentsJoinedByString:#","];
NSString *friendIds = [[NSString alloc] initWithFormat:#"[%#]",friendIdsSeparation ];
[params setObject:friendIds forKey:#"tags"];
}
FBRequest *request = [[[FBRequest alloc] initWithSession:_fbSession graphPath:apiPath parameters:params HTTPMethod:#"POST"] autorelease];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
[SVProgressHUD dismiss];
if (error) {
NSLog(#"Error ===== %#",error.description);
if (_delegate != nil) {
[_delegate facebookConnectFail:error requestType:FBRequestTypePostOnWall];
}else{
NSLog(#"Error ===== %#",error.description);
}
}else{
if (_delegate != nil) {
[_delegate faceboookConnectSuccess:self requestType:FBRequestTypePostOnWall];
}
}
If you followed the tutorial on how to setup Open Graph for iOS, you can do something like this if you use the friendsPickerController:
// Create an action
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
//Iterate over selected friends
if ([friendPickerController.selection count] > 0) {
NSMutableArray *temp = [NSMutableArray new];
for (id<FBGraphUser> user in self.friendPickerController.selection) {
NSLog(#"Friend selected: %#", user.name);
[temp addObject:[NSString stringWithFormat:#"%#", user.id]];
}
[action setTags:temp];
}
Basically, you can set an array of friend's ids on the "tags" property on an action
Can anyone help me. I cannot figure out how to make a single FQL query using the latest Facebook SDK (v 3.1) for iOS to get birthday and email of user's friend. When I query for fields like name i get the correct value but get null for email and birthday field.
Here is my code
- (void)facebookViewControllerDoneWasPressed:(id)sender {
// we pick up the users from the selection, and create a string that we use to update the text view
// at the bottom of the display; note that self.selection is a property inherited from our base class
for (id<FBGraphUser> user in _friendPickerController.selection) {
_nameTxt.text = user.name;
NSString *fql = [NSString stringWithFormat:#"SELECT email, birthday, name FROM user WHERE uid = %# ",user.id];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObject:fql forKey:#"q"];
[FBRequestConnection startWithGraphPath:#"/fql"
parameters:params
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error) {
NSLog(#"Error: %#", [error localizedDescription]);
} else {
NSLog(#"Result: %#", result);
}
}];
}
[self.navigationController dismissModalViewControllerAnimated:YES];
}
I'm getting value for name but null for email and birthday.
Thanks
Before you call your query, you'll need to have the user log in and ask for email and user_birthday permissions. For example:
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"email",
#"user_birthday",
nil];
return [FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];
}
The above method is used in the context of this tutorial:
https://developers.facebook.com/docs/howtos/login-with-facebook-using-ios-sdk/
Also check out the FQL tutorial:
https://developers.facebook.com/docs/howtos/run-fql-queries-ios-sdk/