Facebook Graph Api call not working for iOS - ios

For an iOS app, using facebook sdk i need to fetch photos from user's album but i need to fetch them in a single request so that i could get info about albums and containing photos at the same time, for that i tried
/me/albums?fields=count,name,photos.limit(10){images}
that api call is working fine in Graph api explorer but not on iOS platform. I only need images field of photos that is why using
above api call
If i run this api it runs fine
/me/albums?fields=count,name,photos.limit(10)
only {images} part is causing the problem, the error message which i get is of unsupported url, have acquired the permissions for user_photos
Code :
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:#"/me/albums?fields=count,name,photos.limit(10){images}" parameters:nil HTTPMethod:#"GET"];
FBSDKGraphRequestConnection *connection = [[FBSDKGraphRequestConnection alloc] init];
[connection addRequest:request completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSLog(#"result %#",result);
} else {
NSLog(#"error description : %#",error.description);
}
}];
[connection start];

I was making the final url call by adding/removing fields from graph api explorer side pane, the request call it was generating was
/me/albums?fields=count,name,photos.limit(10){images}
not working on iOS platform, but if i use this syntax instead
/me/albums?fields=count,name,photos.limit(10).fields(images)
to address fields of photos then it works fine, got the inspiration from answer posted here

Related

Facebook Graph, how i can retrive info like lenght for a shared video?

This is the flow i'm trying to create:
i see a public video on facebook and i take the link -> i close facebook ios app -> open my ios app -> paste the link in a textfield -> share the link on my facebook timeline after a login.
The code i use to share the link is:
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:#"https://www.facebook.com/facebookuser/videos/23948249872938/" forKey:#"link"];
[params setObject:[[FBSDKAccessToken currentAccessToken] tokenString] forKey:#"access_token"];
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"/me/feed"
parameters:params
HTTPMethod:#"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
// Handle the result
if (!error) {
}
else{
NSLog(#"error %#",error.description);
}
}];
All works correctly, the trouble comes if i try to retrive some information about the video, like the lenght. I have tried to test a call in Facebook Graph Tool to retrive lenght, i have tried:
GET /v2.6/{video-id} HTTP/1.1
Host: graph.facebook.com
and i have add the length field. Result is this error:
"error": {
"message": "(#100) Tried accessing nonexisting field (length) on node type (Post)",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "xxxxx"
}
Why? Maybe my share isn't view as a video but only as a post? How i can retrive the lenght of this shared video?
Solved myself, the id returned it's a post id, not a video id. In Graph Api length of an attached post video is in "properties" node.

How to Post image on FB Users wall with the message ?(without using URL for image)

I am trying to post on users wall using ios app by using FB New graph API 3.17.1.But when I post using the graph path me/photos, it will create an bunch of post at one location instead of posting the images as separate story.
I did lot of R&D and found this Post photo on user's wall using Facebook iOS SDK
I used below method to post on user's wall
NSMutableDictionary* postParams = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
#"<Image URL>", #"picture",
#"Facebook SDK for iOS", #"name",
#"build apps.", #"caption",
#"testing for my app.", #"description",
nil];
[FBRequestConnection startWithGraphPath:#"me/feed"
parameters:postParams
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result,NSError *error)
{
if (error)
{
NSLog(#"Error in uploading the photo %#",error);
}
}];
This method does paste the image on user's wall but for this image has to be uploaded somewhere on internet and we have supply the URL of same.And additionally it makes image visibility very less compared to image posted using me/potos.
[FBRequestConnection startWithGraphPath:#"me/photos" parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection*connection, id result, NSError *error)
{
NSLog(#"Error : %#",error);
NSLog(#"%#",result);
}];
I used above method but it will group the photos into bunch and make the album on the users wall after 3-4 post. And additionally it has limitation of max 25 post per app per day. So this method is negligible.
Please let me know any alternative way, if anyone has used.I would be very thankful.

Facebook Graph Api v2.0 me/photos returns empty for all users except me who created the app

I am using this code below, which uses the parse sdk:
[PFFacebookUtils initializeFacebook];
[FBSession.activeSession requestNewReadPermissions:#[#"user_photos"] completionHandler:^(FBSession *session, NSError *error) {
if (!error) {FBRequestConnection *connection = [[FBRequestConnection alloc] init];
FBRequest *request = [[FBRequest alloc] initWithSession:[FBSession activeSession]
graphPath:[NSString stringWithFormat:#"me/photos"]];
[connection addRequest:request completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {}];
[connection start];
This all works fine for me it downloads all the most recent photos. But for anyone else, who has logged in via Facebook on the app the result returns:
{
data = (
)
}
Why am i, the developer, the only one who is able to access his photos? Is there a setting in the app settings on Facebook?
From v2.0 onwards, the permissions other than public_profile, email and the user_friends need to the submitted for review before you can make your app live; until then, only the testers/admin/developers of the app will be able to test app with those permissions.
See here for details on the Login Review.
yes there is,
You have to go on you facebook developer account -> go on the application -> add a contact email.
After that go to status & review -> and set Do you want to make this app and all its live features available to the general public? to yes.
Now it should work

Facebook Like Button - canĀ“t build archive with the new feature FBLikeControl

I want to integrate Facebook like Button with the new feature FBLikeControl. On the facebook page they have written it is only for developement and not for publication on the AppStore.
Here is the Tutorial from facebook https://developers.facebook.com/docs/ios/like-button/
When I want to build an archive with my code I get the error message "Use of undeclared identifier FBBetaFeaturesLikeButton".
Is there a way to solve this problem or if there's any other alternative solution, I would appreciate that.
Here is my code:
[FBSettings enableBetaFeature:FBBetaFeaturesLikeButton];
[FBSettings enablePlatformCompatibility:NO];
FBLikeControl *like = [[FBLikeControl alloc] init];
like.frame = CGRectMake((self.frame.size.width-like.frame.size.width)/2, facebookY, 60, 20);
like.objectID = #"https://www.facebook.com/pages/abcdefgh/123456789?ref=tn_tnmn";
[self addSubview: like];
This link says:
FBLikeControl is a preview feature and may not be deployed to the App
Store. Only developers and testers of your Facebook app will be able
to use the Like Button.
is the reason you are unable to built the archive.
There are several ways to implement like, the one which worked for me is as follows:
[FBRequestConnection startWithGraphPath:#"/object-id_to_like/likes"
parameters:nil
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
// Handle error here
}];
Here is the Link
EDIT: It is pretty simple, you just have to replace FBLikeControl code in your project with the above method call replacing object-id_to_like to the actual post-id/ object-id. What the method does is it POSTS a like on corresponding object/post.
In case you have problem to fetch the object id of the object/post you can fetch it using same method with the HTTPMethod parameter set to #"GET". Following code will return posts from your timeline:
[FBRequestConnection startWithGraphPath:#"/me/home"// you can change this to #"/me/feed" if required
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error ) {
if (!error){
// Fetch Post-id/Object-id here
}else{
// handle error here
}
}];

Sharing Video to facebook via FB SDK for iOS

I have a video created in my app.
I want to shared this video to user's Facebook wall via facebook native SDK.
I am able to get the video sharing working, but there is no preview/share dialog shown to the user before sharing. The video is directly posted to user's wall.
Here is my code to get open an active session
[FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceOnlyMe allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error){}
Once I get the session active, I call the below method to share the video
- (void)sendVideoFeedRequestWithParams:(NSMutableDictionary *)params
{
// create the connection object
FBRequestConnection *newConnection = [[FBRequestConnection alloc] init];
// create a handler block to handle the results of the request
FBRequestHandler handler =
^(FBRequestConnection *connection, id result, NSError *error) {
// output the results of the request
[self requestCompleted:connection result:result error:error];
};
// create the request object, using the /me as the graph path
FBRequest *request = [[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:#"me/videos" parameters:params HTTPMethod:#"POST"];
// add the request to the connection object, if more than one request is added
// the connection object will compose the requests as a batch request; whether or
// not the request is a batch or a singleton, the handler behavior is the same,
// allowing the application to be dynamic in regards to whether a single or multiple
// requests are occuring
[newConnection addRequest:request completionHandler:handler];
// if there's an outstanding connection, just cancel
[self.requestConnection cancel];
// keep track of our connection, and start it
self.requestConnection = newConnection;
[newConnection start];
}
The params I am sending to this method are:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
videoData, #"video.mov",
#"video/quicktime", #"contentType",
#"Video Test Title", #"title",
#"Video Test Description", #"description",
nil];
This works well as far as posting the video is concerned. But, I want a share/preview dialog to be shown.
Anybody got any hints on how to get it done?
You need to create something yourself or search for an existing solution on github (or similar). Something like a custom alert view where you can allow the user to enter text, have a thumbnail of the video which plays when tapped and a couple of buttons.

Resources