My request:
<FBRequestConnection: 0x93a8ba0, 1 request(s):(
<FBRequest: 0x9395c90, session: 0xa8aeb80, graphPath: https://graph.facebook.com/me, HTTPMethod: GET, parameters:
{
"access_token" = BAAG4P63ZBHK0BAObimWrMZCGOzn3s6qOtqynyzkJmIN0fKiKGlCkmlqlKMcpbvrrhN9QJsIxrTc7PZCFoceuCwAC2ygCph27WV72iwxkbi2svKCDemDo8BBqOwc6bp6DQH7U9tjp4gZBofb4brYg;
fields = name;
format = json;
"migration_bundle" = "fbsdk:20120913";
sdk = ios;
})>
My response:
result (null)
error Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x93b1ad0 {com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 100;
message = "(#100) Unknown fields: name.";
type = OAuthException;
};
};
code = 400;
}, com.facebook.sdk:HTTPStatusCode=400}
What is the reason behind?
If I send without fields = name; then I get back some default user data.
Invoking:
FBRequest *graphRequest = [[FBRequest alloc] initWithSession:[FBSession activeSession]
graphPath:request.graphPath
parameters:request.parameters
HTTPMethod:request.httpMethod];
FBRequestConnection *connection = [[FBRequestConnection alloc] init];
[connection addRequest:graphRequest
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
[self requestCompleted:connection result:result error:error];
}];
[connection start];
Request object:
-(NSString*)graphPath
{ return #"https://graph.facebook.com/me"; }
-(NSDictionary*)parameters
{
return [NSDictionary dictionaryWithObjectsAndKeys:
#"name", #"fields",
nil];
}
-(NSString*)HTTPMethod
{
return #"GET";
}
Have tried with fixed parametes as well, no effect:
graphRequest = [[FBRequest alloc] initWithSession:[FBSession activeSession]
graphPath:#"https://graph.facebook.com/me"
parameters:[NSDictionary dictionaryWithObjectsAndKeys:#"name", #"fields", nil]
HTTPMethod:#"GET"];
Graph path must be relative.
Now I use only #"me" instead of #"https://graph.facebook.com/me", and works like a charm.
Related
Hi I have recently started coding for iOS.I am trying to get videos from facebook using the following code.
-(void)facebookGetVideos:(UIViewController*)vc completionHandler:(void (^)(NSMutableArray*))completionBlock{
__block NSMutableArray * itemArray;
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"me/videos/uploaded"
parameters:#{#"fields":#"source,description,thumbnail,title"}
HTTPMethod:#"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
if(error!=nil){
NSLog(#"Error after fb dwnld %#",error);
[MBProgressHUD hideHUDForView:vc.view animated:true];
[self showAlert:#"Error" message:error.localizedDescription viewController:vc];
}else{
NSLog(#"Results %#",result);
itemArray = [[NSMutableArray alloc]init];
// [itemArray addObject:[result valueForKey:#"data"]];
itemArray =[result valueForKey:#"data"];
completionBlock(itemArray);
}
}];
}
The response I am getting from there is as below:-
{
data = (
{
id = 1845903302379295;
source = "https://video.xx.fbcdn.net/v/t43.1792-2/27475816_220074475216744_8742438766032977920_n.mp4?efg=eyJybHIiOjE1MDAsInJsYSI6MTAyNCwidmVuY29kZV90YWciOiJzdmVfaGQifQ%3D%3D&rl=1500&vabr=382&oh=d4c3f6028a979c5919fdd8e444e24179&oe=5A89882A";
},
{
id = 1814936632142629;
source = "https://video.xx.fbcdn.net/v/t42.14539-2/23925286_2650490725061654_2502749796398268416_n.mp4?efg=eyJybHIiOjU3NiwicmxhIjo1MTIsInZlbmNvZGVfdGFnIjoic2QifQ%3D%3D&rl=576&vabr=320&oh=2fde1aea6eff33d8139ccb8fe7a33fd4&oe=5A8980C0";
}
);
paging = {
cursors = {
after = MTgxNDkzNjYzMjE0MjYyOQZDZD;
before = MTg0NTkwMzMwMjM3OTI5NQZDZD;
};
};
}
I am trying to use this after before as parameters as below:-
-(void)afterValues:(NSString*)afterVal{
NSDictionary * parameters =#{#"fields":#"source",#"after": afterVal};
FBSDKGraphRequest *request1 = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"me/videos/uploaded"
parameters:parameters
HTTPMethod:#"GET"];
[request1 startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
NSLog(#"after videos%#",result);
}];
}
And getting the following as response:-
after videos{
data = (
);
}
Can anyone please point out at my mistake.Any kind of help/suggestion or guidance in this directions would be highly appreciated.Thanks in advance!
Have you requested the manage_pages permission from the respective user through the login dialog? I think you see an empty result because of the missing permission.
Please help me to solve this below error :
Error Domain=com.facebook.sdk Code=5 "(null)" UserInfo={com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 2500;
"fbtrace_id" = "HkQ+T3pxGRU";
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
};
code = 400;
}, com.facebook.sdk:HTTPStatusCode=400}
I got an error when posting message with image on facebook and i m using latest facebook sdk.
I'm using this below code:
-(void)posting
{
if ([[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"]) {
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:#"hello hii how r u " forKey:#"message"];
[params setObject:UIImagePNGRepresentation(self.img_to_share.image) forKey:#"picture"];
[FBRequestConnection startWithGraphPath:#"me/photos"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
if (error)
{
//showing an alert for failure
NSLog(#"Unable to share the photo please try later.");
}
else
{
//showing an alert for success
NSLog(#"Shared the photo successfully");
}
}];
}
}
Thanks in advance,
Edit:
check after adding access_token in the graph calls since the facebook-ios-sdk doesn't do this automatically.
[FBRequestConnection requestWithGraphPath:[NSString stringWithFormat:#"/me/photos?access_token=%#", FBRequestConnection.accessToken]
andParams:params andHttpMethod:#"POST" andDelegate:self];
For more information check: https://developers.facebook.com/docs/graph-api/reference/user#posts
I am getting attending list of Event by this code.
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[[[FBSession activeSession] accessTokenData] accessToken], #"access token",
#"100000000000",#"limit",
nil];
FBSDKGraphRequest *requestA = [[FBSDKGraphRequest alloc] initWithGraphPath:[NSString stringWithFormat:#"%#/attending",[self.dictData objectForKey:#"FBEventId"]] parameters:params HTTPMethod:#"GET"];
FBSDKGraphRequestConnection *connectionA = [[FBSDKGraphRequestConnection alloc] init];
[connectionA addRequest:requestA completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if(!error)
{
attending = [[result objectForKey:#"data"] count];
[tblDetail reloadData];
}
else
{
attending = 0;
NSLog(#"error description : %#",error.description);
}
}];
[connectionA start];
This is working fine. But if i call it again, It gives me error,
It seems like, It work only once.
Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo=0x7fe846142280 {NSLocalizedDescription=unsupported URL, NSUnderlyingError=0x7fe843ddcb90 "unsupported URL"}
I have access of these Permissions,
Permission : (
"user_events",
"user_friends",
"rsvp_event",
email,
"publish_actions",
"public_profile"
)
Is it enough to do this action ?
Why this is happening ??
Finally I got solution. Actual problem is in my graph request.
Here is a correct one.
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"100000000000",#"limit",
nil];
FBSDKGraphRequest *requestA = [[FBSDKGraphRequest alloc] initWithGraphPath:[NSString stringWithFormat:#"%#/attending",[self.dictData objectForKey:#"FBEventId"]] parameters:params tokenString:[[[FBSession activeSession] accessTokenData] accessToken] version:#"v2.3" HTTPMethod:self.HTTPGet];
FBSDKGraphRequestConnection *connectionA = [[FBSDKGraphRequestConnection alloc] init];
[connectionA addRequest:requestA completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if(!error)
{
attending = [[result objectForKey:#"data"] count];
}
else
{
attending = 0;
NSLog(#"error description : %#",error.description);
}
[tblDetail reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:3 inSection:0], nil] withRowAnimation:UITableViewRowAnimationAutomatic];
}];
[connectionA start];
I'm attempting to post a graph event like so with the new SDK:
FBSDKAccessToken *token = [FBSDKAccessToken currentAccessToken];
FBSDKGraphRequestConnection *connection = [[FBSDKGraphRequestConnection alloc] init];
NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];
action[#"event"] = #"http://samples.ogp.me/680289198752391";
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:#"me/friendlish:add" parameters:action tokenString:token.tokenString version:#"v2.3" HTTPMethod:#"POST"];
//
[connection addRequest:request completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if(error)
NSLog(#"%#", error);
else
NSLog(#"%#", result);
}];
[connection start];
All works fine, and it posts -- but when I try actually changing up the example to something custom like this:
NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];
NSMutableDictionary<FBGraphObject> *event = [FBGraphObject openGraphObjectForPost];
event[#"og:title"] = #"My Event";
event[#"og:type"] = #"friendlish:event";
event[#"og:url"] = #"http://www.facebook.com";
event[#"og:description"] = #"Yaba daba doo";
event[#"og:image"] = #"https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png";
action[#"event"] = event;
I get a first error in console before the connection NSLogs are called:
Unsupported FBSDKGraphRequest attachment:{
data = {
};
"fbsdk:create_object" = 1;
"og:description" = "Yaba daba doo";
"og:image" = "https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png";
"og:title" = "My Event";
"og:type" = "friendlish:event";
"og:url" = "http://www.facebook.com"; }, skipping.
Then the error from the connection method NSLog:
Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL"
UserInfo=0x174077080 {NSLocalizedDescription=unsupported URL,
NSUnderlyingError=0x17445f920 "unsupported URL"}
I want to like a comment of a post on Facebook, I use the same as like the post. For like a post, it works, but for like a comment fail.
Doc:
https://developers.facebook.com/docs/graph-api/reference/object/likes
My Code:
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:#"/%#/likes", postId_]
parameters:nil
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{ //Error:
}];
The Error is:
Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x158999b0 {com.facebook.sdk:HTTPStatusCode=400, com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 100;
message = "(#100) Error finding the requested story";
type = OAuthException;
};
};
code = 400;
}, com.facebook.sdk:ErrorSessionKey=}
Here is how I do it, and it works like a charm
// post is my module object, encapsulates the info form the post
// pass the post ID
NSString *graphPath = [NSString stringWithFormat:#"%#/likes", post.postID];
FBRequest *request = [FBRequest requestForGraphPath:graphPath];
// DELETE or POST the like
NSString *method = post.liked?#"DELETE":#"POST";
[request setHTTPMethod:method];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
BOOL success = YES;
success = (error)?NO:YES;
if(success) {
}
}];
Note: make sure you have publish permissions
In my project I use the following code:
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:URL, #"object", nil];
if (FBSession.activeSession.isOpen) {
if (FBSession.activeSession.accessTokenData.accessToken) {
[FBRequestConnection startWithGraphPath:#"/me/og.likes"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(#"Just liked on Facebook!");
}];
} else NSLog(#"Cannot open FBSession");
}
There no code for opening or initializing FBSession - I hope, it's not a problem?
I think, we all can trust Facebook, yes? :)
Go to https://developers.facebook.com/docs/reference/opengraph/action-type/og.likes, select "IOS SDK" tab and look at the code.