[英]how to get the user name of the currently logged in user using latest facebook graph api
i ve created a facebook application using facebook graph api what i want is to get the user name of the currently logged in user .below is the code 我已经使用facebook graph api创建了一个facebook应用程序,我想要的是获取当前登录用户的用户名。下面是代码
-(IBAction)bomb
{
facebook = [[Facebook alloc] initWithAppId:@"109133762519851"];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
if (![facebook isSessionValid]) {
[facebook authorize:nil delegate:self];
}
}
- (void)fbDidLogin {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
NSLog(@"facebook:%@",defaults);
[facebook dialog:@"stream.publish" andParams:params andDelegate:self]; */
NSMutableDictionary *fbArguments = [[NSMutableDictionary alloc] init];
NSString *wallPost = @"wat de heck";
NSString *linkURL = @"http://www.supersite.com";
NSString *imgURL = @"http://www.supersite.com/image.jpg";
[fbArguments setObject:wallPost forKey:@"message"];
[fbArguments setObject:linkURL forKey:@"link"];
[fbArguments setObject:imgURL forKey:@"picture"];
//NSLog(@"username:%@",facebook.);
[facebook requestWithGraphPath:@"me/feed"
andParams:fbArguments
andHttpMethod:@"POST"
andDelegate:self];
}
#pragma mark FBRequestDelegate methods
- (void)request:(FBRequest*)request didLoad:(id)result
{
if ([request.method isEqualToString:@"facebook.fql.query"])
{
NSArray* users = result;
NSDictionary* user = [users objectAtIndex:0];
NSString* name = [user objectForKey:@"name"];
username = name;
[username retain];
}
- (void)getFacebookName
{
NSString* fql = [NSString stringWithFormat:@"select uid,name from user where uid == %lld", session.uid];
NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"];
[[FBRequest requestWithDelegate:self] call:@"facebook.fql.query" params:params];
}
you need to import these 2 classes and implement this protocal 您需要导入这两个类并实现此协议
#import "FBConnect/FBConnect.h"
#import "FBConnect/FBSession.h"
FBRequestDelegate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.