the*_*ncs 12 iphone facebook objective-c facebook-graph-api ios
我正在写一款iPhone游戏,并希望将用户的分数发布到他们的Facebook Feed中.
我已经成功地将用户同意授权的示例拼凑在一起,然后出现一个对话框,他们可以确认在他们的墙上发布,或者不发布.这几乎是理想的,除了文本是可编辑的字段 - 因此用户可以修改他们的分数然后发布.理想情况下,我想要完全相同的机制,但没有能力修改消息.
我假设这样做,我需要询问publish_stream权限,然后使用Graph api调用来发布消息.我采购了这个,但收到错误'必须使用活动访问令牌来查询有关当前用户的信息.'.
我很乐意在实际的代码更改中指出正确的方向 - 任何帮助都非常感激.
这是我的第一篇stackOverflow帖子,请温柔.
多谢你们.
-Duncan
原始代码(发布到墙上但带有可修改的文本框)
//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];
Run Code Online (Sandbox Code Playgroud)
直接发布到墙上的代码(未证明)(引发活动令牌错误):
/*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);
Run Code Online (Sandbox Code Playgroud)
the*_*ncs 12
找到解决方案 应首先调用身份验证.经过身份验证后,这将调用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];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23107 次 |
| 最近记录: |