gpt4 book ai didi

iphone - 如何使用 Facebook SDK 发布到用户墙上

转载 作者:可可西里 更新时间:2023-11-01 03:06:01 26 4
gpt4 key购买 nike

我想在 iOS 应用程序中使用 facebook sdk 将一些文本发布到用户墙上。

现在发布开放图表故事是唯一的方法吗?

我发现开放式图表故事真的很奇怪,你只能以“用户 x a y”的格式发布内容,你可以直接在 facebook 上预设 x 和 y,例如用户在吃披萨或玩游戏。设置每一个也非常费力,因为您必须在外部服务器上为每一个创建一个 .php 对象。

我是不是遗漏了什么或者是否有更简单的方法来解决这个问题?

最佳答案

通过多浏览 facebook 教程弄清楚了。

-(void) postWithText: (NSString*) message
ImageName: (NSString*) image
URL: (NSString*) url
Caption: (NSString*) caption
Name: (NSString*) name
andDescription: (NSString*) description
{

NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
url, @"link",
name, @"name",
caption, @"caption",
description, @"description",
message, @"message",
UIImagePNGRepresentation([UIImage imageNamed: image]), @"picture",
nil];

if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound)
{
// No permissions found in session, ask for it
[FBSession.activeSession requestNewPublishPermissions: [NSArray arrayWithObject:@"publish_actions"]
defaultAudience: FBSessionDefaultAudienceFriends
completionHandler: ^(FBSession *session, NSError *error)
{
if (!error)
{
// If permissions granted and not already posting then publish the story
if (!m_postingInProgress)
{
[self postToWall: params];
}
}
}];
}
else
{
// If permissions present and not already posting then publish the story
if (!m_postingInProgress)
{
[self postToWall: params];
}
}
}

-(void) postToWall: (NSMutableDictionary*) params
{
m_postingInProgress = YES; //for not allowing multiple hits

[FBRequestConnection startWithGraphPath:@"me/feed"
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
if (error)
{
//showing an alert for failure
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Post Failed"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
m_postingInProgress = NO;
}];
}

关于iphone - 如何使用 Facebook SDK 发布到用户墙上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15783453/

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