There are some differences between the Facebook graph API versions 1.0 and 2.0 that I'm not so fond of so I would like to downgrade to the graph API version 1.0.
Any ideas how to do this?
Here's the code I'm using right now, which makes a call to version 2.0:
[FBRequestConnection startWithGraphPath:#"/me/friends"
parameters:[NSDictionary dictionaryWithObjectsAndKeys:#"20", #"limit", nil]
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Sucess! Include your code to handle the results here
NSLog(#"***** user friends with params: %#", result);
} else {
// An error occurred, we need to handle the error
}
}];
while the above answer is correct you can use
[FBSettings enablePlatformCompatibility: YES];
And all FbRequests target api v1.0 here is the official documentation about this:
https://developers.facebook.com/docs/reference/ios/current/class/FBSettings/
And if you want to target individual request that use of v1.0 of graph api you can specify it like this:
[FBRequestConnection startWithGraphPath:#"v1.0/me/friends"
parameters:[NSDictionary dictionaryWithObjectsAndKeys:#"20", #"limit", nil]
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Sucess! Include your code to handle the results here
NSLog(#"***** user friends with params: %#", result);
} else {
// An error occurred, we need to handle the error
}
}];
And here is the official docs that explains this
https://developers.facebook.com/docs/reference/ios/current/class/FBRequest/
See overrideVersionPartWith: method and Discussion of it
This can be accomplished at the FBRequest level.
You need to create the FBRequest yourself and use overrideVersionPartWith:.
Keep in mind this will only work if your Facebook app was created before the v2.0 API was released. Newer apps are blocked from using the old API at all.
It will look something like this:
FBRequest *request = [FBRequest requestWithGraphPath:#"/me/friends"
parameters:[NSDictionary dictionaryWithObjectsAndKeys:#"20", #"limit", nil]
HTTPMethod:#"GET"];
[request overrideVersionPartWith:#"v1.0"];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Success! Include your code to handle the results here
NSLog(#"***** user friends with params: %#", result);
} else {
// An error occurred, we need to handle the error
}
}];
Related
In my app i need to upload a video to the user's facebook wall. I use this code and it works:
[FBRequestConnection startWithGraphPath:#"me/videos"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
if (error)
{
//showing an alert for failure
}
else
{
//showing an alert for success
}
}];
I wanna add a progress bar during the upload time... but i can't find anything that works...I have read the documentation also, but i can't find anything... There is a way manage a progress bar for #"me/videos" ?
You can set a FBRequestConnectionDelegate on the FBRequestConnection, see https://developers.facebook.com/docs/reference/ios/current/protocol/FBRequestConnectionDelegate/, and implement the requestConnection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite method.
Your progress should be totalBytesWritten/totalBytesExpectedToWrite.
You also need to create the FBRequest and the FBRequestConnection separately if you want to set the delegate, something like:
FBRequest *request = [FBRequest requestForUploadVideo:#"some_path"];
FBRequestConnection *connection = [[FBRequestConnection alloc] init];
[connection addRequest:request completionHandler:YOUR_HANDLER_HERE];
connection.delegate = self;
[connection start];
I am trying fetch my Friends who are using my application from facebook and but in the response i am getting empty list list. Please guide me what i am doing wrong. I am using the following code
[[FBRequest requestForMe] startWithCompletionHandler: ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (error) {
//error
NSLog(#"%#",error);
}else{
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,NSDictionary* result,NSError *error) {
NSArray* friends = [result objectForKey:#"data"];
NSLog(#"%#",result);
for (NSDictionary<FBGraphUser>* friend in friends)
{
NSLog(#"%# %d",friend.username,[friend.id intValue]);
}
}];
}
}];
Thanks
Possible reasons:
1) You don't have the rights to get connections of this account (wrong apikey/passkey or rights not properly set)
2) Check what is stored in "result" variable and the answer status: it may guide you in some way.
3) Finally, try to get some simpler informations (like your own username) to be sure you have access to these informations.
In the new version of Facebook's API you will get ONLY friends that installed the app (i.e. is_app_user is 1).
You can't get friends who haven't logged in with your app anymore.
Instead, you can get taggable_friends. This will return a list with all of your friends, but here "id" field will be different, not the real facebook id. Its only for tagging, i.e. for passing to field "tags" like:
NSDictionary *params = #{#"message":self.invitationText.text,
#"tags":ids,
#"caption":#"...",
#"name":#"...",
#"place":#"123456789",
#"link":APP_STORE_URL};
[FBRequestConnection startWithGraphPath:#"/me/feed"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
//...
}];
I am using Facebook graph api in my app. I want to get user's posted videos. When I login I get basic info. But when i query about posts i only get id in result.
My code is:
-(void)getPosts {
NSMutableDictionary *par = [[NSMutableDictionary alloc]init];
[par setObject:#"posts" forKey:#"fields"];
[FBRequestConnection startWithGraphPath:#"me"
parameters:par
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
)
{
//handle the result
if(!error)
{
NSLog(#"%#",result);
}
else
{
NSLog(#"%#",[error localizedDescription]);
}
}];
}
Please help if I am doing wrong or missing something. Thanks in advance
with the referance from facebook dev API
https://developers.facebook.com/docs/graph-api/reference/v2.0/user/videos
you got Logged in User Video using this method:
/* make the API call */
[FBRequestConnection startWithGraphPath:#"/me/videos"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
/* handle the result */
}];
it's Filed object is
You need to set first Permission of user_videos as par doc said:
A user access token with user_videos permission is required to see all videos that person is tagged in or has uploaded.
HERE IT IS SAMPLE CODE:
http://www.filedropper.com/fblogin
1) Here is a basic logic to get User's uploaded video...(shows all videos that were published to Facebook by user)
/* make the API call */
[FBRequestConnection startWithGraphPath:#"me/videos/uploaded"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
/* handle the result */
arrFbUserUploadVideos= [result objectForKey:#"data"]; //get all data in NSMutableArray
}];
Note: This will give the video Uploaded by the user..
2) and if you also want video list in which User tag (shows all videos use person is tagged in) in that case
/* make the API call */
[FBRequestConnection startWithGraphPath:#"me/videos"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
/* handle the result */
arrFbUserTagVideos= [result objectForKey:#"data"]; //get all data in NSMutableArray
}];
Note: This will give the video in which user is tag..
HERE IS A REFERENCE LINK:
i am using the ios sdk 3.0 to post simple text to user facebook wall , below is the code is use to post to facebook
[FBRequestConnection
startForPostStatusUpdate:text completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
if (!error)
{
NSLog(#"the status posted");
}
}];
but i get the error from facebook like
FBSDKLog: Response <#1115> :
The operation couldn’t be completed. (com.facebook.sdk error 5.) . any help would be appreciated.
The bug is if you try to share an NSString.
This works:
[FBRequestConnection startForPostStatusUpdate:#"test"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
}];
This gives you the error:
NSString *testString = #"test";
[FBRequestConnection startForPostStatusUpdate:testString
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
}];
I am running into issues trying upgrade my Facebook SDK to the latest production release (FacebookSDK-3.0.8.pkg - Facebook SDK 3.0 for iOS (update 1) [August 21, 2012]).
I am following along with tutorial on this page.
I have ran into several issues trying to get the code to work, it's not as easy as it proclaims to be in the tutorial. I can get my session open, but can not get the request to work.
- (IBAction)facebookTapped:(id)sender {
[FBSession openActiveSessionWithPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if(error) {
NSLog(#"Error opening session: %#", error);
return;
}
if(session.isOpen) {
NSLog(#"session is open");
FBRequest *me = [FBRequest requestForGraphPath:#"me"];
[me startWithCompletionHandler:^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *my,
NSError *error) {
NSLog(#"My name: %#", my.first_name);
}];
}
}];
}
My console displays that the session is open if I remove the call to FBRequest requestforGraphpath. If I leave it in, I receive the error "Incompatible block pointer types initializing 'void(^)(struct FBRequestConection , struct NSDictionary, struct NSError*)', expected 'FBRequestHandler'
Now what has me stumped is that this is the exact code shown in the tutorial, excpet that I changed out [FBRequest requestForMe] trying different approaches. None worked.
Can anyone shed some light on this for me?
Thank you.
I was able to solve this issue by changing their original block in the tutorial of:
if (session.isOpen) {
FBRequest *me = [FBRequest requestForMe];
[me startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *my,
NSError *error) {
self.label.text = my.first_name;
}];
}
to
if(session.isOpen) {
FBRequest *me = [FBRequest requestForMe];
[me startWithCompletionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
NSDictionary<FBGraphUser> *my = (NSDictionary<FBGraphUser> *) result;
NSLog(#"My dictionary: %#", my.first_name);
}];
}