gpt4 book ai didi

iphone - 如何在没有用户修改消息的情况下从 iOS 应用程序发布到 facebook 墙

转载 作者:技术小花猫 更新时间:2023-10-29 10:35:25 26 4
gpt4 key购买 nike

我正在编写一个 iPhone 游戏,并希望将用户的分数发布到他们的 Facebook 提要中。

我设法拼凑了一个用户同意授权的示例,然后出现一个对话框,他们可以确认在他们的墙上发布,或者不发布。这几乎是理想的,除了文本是一个可编辑的字段——这样用户可以修改他们的分数然后发布。理想情况下,我想要完全相同的机制,但无法修改消息

我假设要这样做,我需要请求 publish_stream 权限,然后调用 Graph api 来发布消息。我找到了这个,但收到错误消息“必须使用事件访问 token 来查询有关当前用户的信息。”。

我会很高兴地指出实际代码更改的正确方向 - 非常感谢任何帮助。

这是我的第一篇 stackOverflow 帖子,所以请保持温和。

谢谢你们。

-邓肯

原始代码(发布到墙上但带有可修改的文本框)

 //offer to facebook connect your score
facebook = [[Facebook alloc] initWithAppId:@"210645928948875"];
[facebook authorize:nil delegate:self];

NSMutableString *facebookMessage = [NSMutableString stringWithString:@"I scored a whopping "];
[facebookMessage appendString: [NSMutableString stringWithFormat:@"%d", currentScore]];
[facebookMessage appendString: [NSMutableString stringWithString:@". Can you beat me?"]];

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"210645928948875", @"app_id",
@"http://duncan.co.uk/", @"link",
@"http://d.yimg.com/gg/goran_anicic/dunc.jpeg", @"picture",
@"dunc", @"name",
//@"Reference Documentation", @"caption",
@"Download the app NOW from the App Store", @"description",
facebookMessage, @"message",
nil];

[facebook dialog:@"stream.publish" andParams:params andDelegate:self];

直接发布到墙上的代码(未证明)(引发事件 token 错误):

/*Facebook Application ID*/
NSString *client_id = @"210645928948875";

//alloc and initalize our FbGraph instance
self.fbGraph = [[FbGraph alloc] initWithFbClientID:client_id];

//begin the authentication process..... andExtendedPermissions:@"user_photos,user_videos,publish_stream,offline_access"
[fbGraph authenticateUserWithCallbackObject:self andSelector:@selector(fbGraphCallback:) andExtendedPermissions:@"user_photos,user_videos,publish_stream,offline_access"];

NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:4];

[variables setObject:@"the message" forKey:@"message"];
[variables setObject:@"http://duncan.co.uk" forKey:@"link"];
[variables setObject:@"bold copy next to image" forKey:@"name"];
[variables setObject:@"plain text score." forKey:@"description"];

FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:@"me/feed" withPostVars:variables];
NSLog(@"postMeFeedButtonPressed: %@", fb_graph_response.htmlResponse);

最佳答案

已找到解决方案。应首先调用身份验证。一旦通过身份验证,这将调用 fbGraphCallback 函数,该函数将执行用户流的发布。

所有这一切都是由 http://www.capturetheconversation.com/technology/iphone-facebook-oauth2-graph-api 提供的。奖励积分归于 The Mad Gamer。非常感谢。

-(IBAction)buttonPublishOnFacebookPressed:(id)sender {
/*Facebook Application ID*/
NSString *client_id = @"123456789012345";

//alloc and initalize our FbGraph instance
self.fbGraph = [[FbGraph alloc] initWithFbClientID:client_id];

//begin the authentication process.....
[fbGraph authenticateUserWithCallbackObject:self andSelector:@selector(fbGraphCallback:)
andExtendedPermissions:@"publish_stream" andSuperView:self.view];
}

-(void)fbGraphCallback:(id)sender {

if ((fbGraph.accessToken == nil) || ([fbGraph.accessToken length] == 0)) {

NSLog(@"You pressed the 'cancel' or 'Dont Allow' button, you are NOT logged into Facebook...I require you to be logged in & approve access before you can do anything useful....");

} else {
NSLog(@"------------>CONGRATULATIONS<------------, You're logged into Facebook... Your oAuth token is: %@", fbGraph.accessToken);

NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:4];

[variables setObject:@"http://farm6.static.flickr.com/5015/5570946750_a486e741.jpg" forKey:@"link"];
[variables setObject:@"http://farm6.static.flickr.com/5015/5570946750_a486e741.jpg" forKey:@"picture"];
[variables setObject:@"You scored 99999" forKey:@"name"];
[variables setObject:@" " forKey:@"caption"];
[variables setObject:@"Download my app for the iPhone NOW." forKey:@"description"];

FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:@"me/feed" withPostVars:variables];
NSLog(@"postMeFeedButtonPressed: %@", fb_graph_response.htmlResponse);

//parse our json
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *facebook_response = [parser objectWithString:fb_graph_response.htmlResponse error:nil];
[parser release];

NSLog(@"Now log into Facebook and look at your profile...");
}

[fbGraph release];
}

关于iphone - 如何在没有用户修改消息的情况下从 iOS 应用程序发布到 facebook 墙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5377584/

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