[英]Post to friends wall with IOS SDK 3.0
I am able to post images on users wall with the following :- 我可以使用以下内容在用户墙上发布图片:-
if (appDelegate.session.isOpen)
{
FBSession.activeSession = appDelegate.session;
[FBRequestConnection startForUploadPhoto:img
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
[self showAlert:@"eCard Posted" result:result error:error];
}];
}
Now the requirement is to pick friends from friend picker class and post the image on the selected friends wall/timeline. 现在,要求是从“好友选择器”类中选择好友,并将图像发布到所选的好友墙上/时间轴上。
I have integrated the Friends picker class as follows:- 我将“朋友选择器”类集成如下:
if (appDelegate.session.isOpen)
{
FBSession.activeSession = appDelegate.session;
if (self.friendPickerController == nil) {
// Create friend picker, and get data loaded into it.
self.friendPickerController = [[FBFriendPickerViewController alloc] init];
self.friendPickerController.title = @"Pick Friends";
self.friendPickerController.delegate = self;
}
[self.friendPickerController loadData];
[self.friendPickerController clearSelection];
[self presentModalViewController:self.friendPickerController animated:YES];
}
Now in the delegate method :- 现在在委托方法中:-
- (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
//UIImage *img = self.image;
FBSession.activeSession = appDelegate.session;
for (id<FBGraphUser> user in self.friendPickerController.selection) {
FBSession.activeSession = appDelegate.session;
if (appDelegate.session.isOpen)
{
NSMutableDictionary *postVariablesDictionary = [[NSMutableDictionary alloc] init];
// [postVariablesDictionary setObject:@"me" forKey:@"name"];
// [postVariablesDictionary setObject:self.image forKey:@"picture"];
[postVariablesDictionary setObject:@"Sample Text" forKey:@"message"];
NSLog(@"%@",user.id);
[FBRequestConnection startForPostWithGraphPath:[NSString stringWithFormat:@"%@/feed",user.id] graphObject:[NSDictionary dictionaryWithDictionary:postVariablesDictionary] completionHandler:nil];
}
else
{
if (appDelegate.session.state != FBSessionStateCreated) {
// Create a new, logged out session.
appDelegate.session = [[FBSession alloc] init];
}
// if the session isn't open, let's open it now and present the login UX to the user
[appDelegate.session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
}];
}
}
[self dismissModalViewControllerAnimated:YES];
} }
The above Delegate method is always leads to a Error code =5 facebook sdk error . 上面的Delegate方法始终导致错误代码= 5 facebook sdk error。 What API should be called to make the above image get posted in the selected friends wall. 应该调用什么API才能使上面的图像发布在所选的朋友墙上。
Please Help me....... 请帮我.......
Finally i am able to post images on the friends wall. 最后,我能够在朋友墙上张贴图像。
The Delegate Method modified as follows :-- 代表方法修改如下:
- (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
//UIImage *img = self.image;
FBSession.activeSession = appDelegate.session;
if (appDelegate.session.isOpen)
{
[FBSession openActiveSessionWithPermissions:[NSArray arrayWithObjects:@"publish_stream",@"user_photos",@"", nil]
allowLoginUI:NO
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
if (error) {
NSLog(@"error");
} else {
[FBSession setActiveSession:appDelegate.session];
}
}];
for (id<FBGraphUser> user in self.friendPickerController.selection) {
if (appDelegate.session.isOpen)
{
FBSession.activeSession = appDelegate.session;
NSMutableDictionary *postVariablesDictionary = [[NSMutableDictionary alloc] init];
[postVariablesDictionary setObject:self.image forKey:@"source"];
// [postVariablesDictionary setObject:UIImagePNGRepresentation(self.image) forKey:@"source"];
[postVariablesDictionary setObject:@"my image" forKey:@"message"];
NSLog(@"%@",user.id);
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%@/photos",user.id] parameters:postVariablesDictionary HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
[self showAlert:@"eCard Posted" result:result error:error];
}];
}
else
{
if (appDelegate.session.state != FBSessionStateCreated) {
// Create a new, logged out session.
appDelegate.session = [[FBSession alloc] init];
}
// if the session isn't open, let's open it now and present the login UX to the user
[appDelegate.session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
}];
}
}
}
[self dismissModalViewControllerAnimated:YES];
} }
Regard and thanks.... 谢谢,谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.