gpt4 book ai didi

ios - 使用IOS SDK 3.0发布到 friend 墙

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:48:10 25 4
gpt4 key购买 nike

我可以通过以下方式在用户墙上发布图片:-

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];
}];

}

现在的要求是从 friend 选择器类中选择 friend ,并将图像发布到所选 friend 的墙/时间轴上。

我已经按如下方式集成了好友选择器类:-

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];


}

现在在委托(delegate)方法中:-

- (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];

上面的 Delegate 方法总是导致 Error code =5 facebook sdk error 。应该调用什么 API 才能使上面的图像发布到选定的 friend 墙。

请帮帮我......

最佳答案

我终于可以在 friend 墙上发布图片了。

委托(delegate)方法修改如下:--

- (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];

关注并感谢....

关于ios - 使用IOS SDK 3.0发布到 friend 墙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12760150/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com