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];
Related
Seems like Facebook iOS SDK v4.0 has a lot of changes. I try to get a user's friends list after he login.
I think it's something to do with FBSDKGraphRequestConnection but I'm not sure how it can be used.
Also, if I only want to get friends who are using my app, does facebook sdk support that?
Can anyone give some examples? Thanks!
FBSDKGraphRequest *friendsRequest =
[[FBSDKGraphRequest alloc] initWithGraphPath:#"me/friends"
parameters:parameters];
FBSDKGraphRequestConnection *connection = [[FBSDKGraphRequestConnection alloc] init];
[connection addRequest:friendsRequest
completionHandler:^(FBSDKGraphRequestConnection *innerConnection, NSDictionary *result, NSError *error) {
...
}];
// start the actual request
[connection start];
This shows how to handle the response:
[[[FBSDKGraphRequest alloc] initWithGraphPath:#"me/friends" parameters:nil]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
{
if (!error)
{
NSArray * friendList = [result objectForKey:#"data"];
for (NSDictionary * friend in friendList)
{
NSLog(#"Friend id: %#", friend[#"id"]);
NSLog(#"Friend name: %#", friend[#"name"]);
}
}
}];
I used below code to get friend list
self.graphrequest = [[FBSDKGraphRequest alloc] initWithGraphPath:#"me/taggable_friends?limit=100"
parameters:#{ #"fields":#"id,name,picture.width(100).height(100)"}];
[self.graphrequest startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
self.resultsArray = result[#"data"];
[self.fbTableView reloadData];
[self.fbTableView setHidden:NO];
} else {
NSLog(#"Picker loading error:%#",error.userInfo[FBSDKErrorLocalizedDescriptionKey]);
}
}];
You can limit the number of friends using limit keyword.Ex: limit=100
I want to retrieve all my photo album from my Facebook account. I follow Graph API also and using latest Facebook API.
My code is like this:
-(IBAction)getgallery:(id)sender
{
FBRequest *request = [FBRequest requestForGraphPath:#"me/albums"];
[request startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary <FBGraphUser> *my, NSError *error) {
if ([my[#"data"]count]) {
for (FBGraphObject *obj in my[#"data"]) {
FBRequest *r = [FBRequest requestForGraphPath:[NSString stringWithFormat:#"/%#/photos", obj[#"id"]]];
[r startWithCompletionHandler:^(FBRequestConnection *c, NSDictionary <FBGraphUser> *m, NSError *err) {
//here you will get pictures for each album
}];
}
}
}];
}
I follow this link. But can't understanding properly. Please anyone can help me?
Nothing is happening when i press the getgallery button.
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
}
}];
I want to post comment on particular photo...how can i achieve that using FBRequestConnection (Graph API), I also used Graph API Explorer, but i am not getting how to do that.please can any one explain me in brief.?
Thanks
If you use graphAPI you try with this code..
NSString *commentid=[NSString stringWithFormat:#"%#/comments",groupId];
NSMutableDictionary *dictVar=[[NSMutableDictionary alloc]init];
[dictVar setValue:textView.text forKey:#"message"];
FbGraphResponse *response=[fbgraph doGraphPost:commentid withPostVars:dictVar];
NSLog(#"%#",response.htmlResponse);
Hope this helps :)
To post a comment on any {object_id} use the following snippet of code
NSDictionary *param = #{#"message": commentText};
FBRequestConnection *connection = [[FBRequestConnection alloc] init];
FBRequest *request = [FBRequest requestWithGraphPath:[NSString stringWithFormat:#"/%#/comments",mediaId] parameters:param HTTPMethod:#"POST"];
[connection addRequest:request completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error) {
aCompletion(NO);
}else{
aCompletion(YES);
}
}];
[connection start];
Hope this will be helpful.
I am using the following code to upload an image to Facebook wall :
UIImage *img = [UIImage imageNamed:#"logoits.png"];
[FBRequestConnection startForUploadPhoto:img
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(#"Facebook posting %#",result);
NSLog(#"Facebook posting %#",error);
}];
It works as expected but I would like to add a message or title to this uploaded photo, and looking at the documentation of FBRequestConnection there is no example of that. http://developers.facebook.com/docs/sdk-reference/iossdk/3.0/class/FBRequestConnection/
How do I upload an image with message?
In the Facebook SDK 3.0 only a image can be post using the given methods, and for other actions you need to use graph a pi's.
So for post a image with message you need to use graph-api. Here is the line of codes which lets you to post a image with message on users timeline.
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:#"your custom message" forKey:#"message"];
[params setObject:UIImagePNGRepresentation(_image) forKey:#"picture"];
_shareToFbBtn.enabled = NO; //for not allowing multiple hits
[FBRequestConnection startWithGraphPath:#"me/photos"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
if (error)
{
//showing an alert for failure
[self alertWithTitle:#"Facebook" message:#"Unable to share the photo please try later."];
}
else
{
//showing an alert for success
[UIUtils alertWithTitle:#"Facebook" message:#"Shared the photo successfully"];
}
_shareToFbBtn.enabled = YES;
}];
and also make sure _shareToFbBtn is enabled only after login is success.
linesvishy's solution works great and it's also worth to note that if you were using Facebook SDK 3.1 and you used method
FBRequest *request = [FBRequest requestForUploadPhoto:_imageToShare];
You can just use the following lines to replace it:
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:_textToShare forKey:#"message"];
[params setObject:_imageToShare forKey:#"picture"];
FBRequest *request = [FBRequest requestWithGraphPath:#"me/photos" parameters:params HTTPMethod:#"POST"];
Hope it helps! Happy Coding!
Here is an example that posts and image and a note:
http://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/publish-open-graph-story/