Ios 如何使用适用于iPhone的Facebook Graph API发布到好友墙
我想在用户朋友的墙上贴些东西 我用它发布到用户墙中Ios 如何使用适用于iPhone的Facebook Graph API发布到好友墙,ios,facebook-graph-api,facebook-ios-sdk,Ios,Facebook Graph Api,Facebook Ios Sdk,我想在用户朋友的墙上贴些东西 我用它发布到用户墙中 SBJSON *jsonWriter = [[SBJSON new] autorelease]; NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys: @"Always Runn
SBJSON *jsonWriter = [[SBJSON new] autorelease];
NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
@"Always Running",@"text",@"http://itsti.me/",@"href", nil], nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
@"a long run", @"name",
@"The Facebook Running app", @"caption",
@"it is fun", @"description",
@"http://itsti.me/", @"href", nil];
NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"Share on Facebook", @"user_message_prompt",
actionLinksStr, @"action_links",
attachmentStr, @"attachment",nil];
[facebook dialog:@"feed"
andParams:params
andDelegate:self];
但是我需要在我朋友的墙上贴。我该怎么做
在这篇文章中,他们提到了targetId,我是否需要对此做些什么。您是否尝试过使用
[facebook requestWithGraphPath:@"[friend_ID]/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];
更新:
朋友墙上的帖子将不再适用于Graph API。相反,您必须使用FBDialog。@mAc
你必须先授权facebook。然后对类实现“FBRequestDelegate”方法。然后使用graph API发出请求,如下所示
[facebook requestWithGraphPath:@"/me/friends" andDelegate:self];
请求成功后,api将调用委托方法“RequestDddLoad”
-(void)request:(FBRequest *)request didLoad:(id)result {
NSLog(@"Result: %@", result);
}
从结果中,您将获得frieds页面ID-(iAction)InviteAction:(ID)sender//按钮操作
- (IBAction)InviteAction:(id)sender // Button action
{
if (!FBSession.activeSession.isOpen) {
// if the session is closed, then we open it here, and establish a handler for state changes
[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Invite friends process cancelled"
message:nil
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
} else if (session.isOpen) {
[self InviteAction:sender];
}
}];
return;
}
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 presentViewController:self.friendPickerController animated:YES completion:nil];
}
- (void) performPublishAction:(void (^)(void)) action
{
if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound)
{
[FBSession.activeSession requestNewPublishPermissions:@[@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
action();
} else if (error.fberrorCategory != FBErrorCategoryUserCancelled){
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Permission denied"
message:@"Unable to get permission to post"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}];
} else {
action();
}
}
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
user:(id<FBGraphUser>)user
{
self.loggedInUser = user;
}
- (void)facebookViewControllerDoneWasPressed:(id)sender
{
NSMutableString *text = [[NSMutableString alloc] init];
for (id<FBGraphUser> user in self.friendPickerController.selection)
{
if ([text length]) {
[text appendString:@","];
}
[text appendString:[NSString stringWithFormat:@"%@",user.id]];
}
//For post to friend's wall
NSDictionary *params = @{
@"name" : @"Hello Please checkout this app",
@"caption" : @" IOS APP",
@"description" : @"",
@"picture" : @"logo@2x.png",
@"link" : @"http:www.google.com",
@"to":text,
};
// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
NSLog(@"Error publishing story.");
UIAlertView *alertshow = [[UIAlertView alloc]initWithTitle:@"Failed" message:@"Failed to Post" delegate:Nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alertshow show];
} else {
if (result == FBWebDialogResultDialogNotCompleted)
{
NSLog(@"User canceled story publishing.");
UIAlertView *alertshow = [[UIAlertView alloc]initWithTitle:@"Failed" message:@"Failed to post on your friend wall" delegate:Nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alertshow show];
} else {
NSLog(@"Story published.");
UIAlertView *alertshow = [[UIAlertView alloc]initWithTitle:@"Success" message:@"Posted on Friend wall" delegate:Nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alertshow show];
}
}}];
[self fillTextBoxAndDismiss:text.length > 0 ? text : @"<None>"];
}
- (void)facebookViewControllerCancelWasPressed:(id)sender {
[self fillTextBoxAndDismiss:@"<Cancelled>"];
}
- (void)fillTextBoxAndDismiss:(NSString *)text
{
[self dismissModalViewControllerAnimated:YES];
}
{
如果(!FBSession.activeSession.isOpen){
//如果会话已关闭,那么我们将在此处打开它,并为状态更改建立一个处理程序
[FBSession openActiveSessionWithReadPermissions:无
阿洛洛洛吉努伊:是的
completionHandler:^(FBSession*会话,
FBSessionState州,
N错误*错误){
如果(错误){
UIAlertView*alertView=[[UIAlertView alloc]initWithTitle:@“邀请好友进程已取消”
信息:无
代表:无
取消按钮:@“确定”
其他按钮:无];
[警报视图显示];
}else if(session.isOpen){
[自邀请动作:发送方];
}
}];
返回;
}
if(self.friendPickerController==nil){
//创建好友选择器,并将数据加载到其中。
self.friendPickerController=[[FBFriendPickerViewController alloc]init];
self.friendPickerController.title=@“选择朋友”;
self.friendPickerController.delegate=self;
}
[self.FrienderPickerController loadData];
[self.FrienderPickerController清除选择];
[self-presentViewController:self.FriendsPickerController动画:是完成:无];
}
-(作废)执行公告:(作废)(作废)行为
{
if([FBSession.activeSession.permissions indexOfObject:@“发布操作”]==NSNotFound)
{
[FBSession.activeSession requestNewPublishPermissions:@[@“发布操作”]
默认观众:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession*会话,NSError*错误){
如果(!错误){
动作();
}else if(error.fberrorCategory!=FBErrorCategoryUserCancelled){
UIAlertView*alertView=[[UIAlertView alloc]initWithTitle:@“权限被拒绝”
消息:@“无法获得发布权限”
代表:无
取消按钮:@“确定”
其他按钮:无];
[警报视图显示];
}
}];
}否则{
动作();
}
}
-(无效)loginView蚀刻教育信息:(FBLoginView*)loginView
用户:(id)用户
{
self.loggedInUser=用户;
}
-(无效)已按下FaceBookViewControllerDone:(id)发件人
{
NSMutableString*text=[[NSMutableString alloc]init];
for(self.friendPickerController.selection中的用户id)
{
如果([文本长度]){
[文本附件字符串:@“,”];
}
[文本附录字符串:[NSString stringWithFormat:@“%@”,user.id]];
}
//贴到朋友的墙上
NSDictionary*参数=@{
@“名称”:@“您好,请签出此应用程序”,
@“标题”:@“IOS应用程序”,
@“说明”:@“,
@“图片”:logo@2x.png",
@“链接”:@“http:www.google.com”,
@“to”:文本,
};
//调用对话框
[FBWebDialogs presentFeedDialogModallyWithSession:无
参数:params
处理程序:
^(FBWebDialogResult、NSURL*resultURL、NSError*error){
如果(错误){
NSLog(@“错误发布故事”);
UIAlertView*alertshow=[[UIAlertView alloc]initWithTitle:@“失败”消息:@“未能发布”委托:Nil cancelButtonTitle:@“确定”其他ButtonTitles:Nil];
[警报秀];
}否则{
如果(结果==FBWebDialogResultDialogOnToCompleted)
{
NSLog(@“用户已取消故事发布”);
UIAlertView*alertshow=[[UIAlertView alloc]initWithTitle:@