因爲我不是專家的編碼器,所以我很難使用Facebook iOS SDK參考。我只是有這個簡單的問題。Facebook iOS SDK:如何獲取用戶的Facebook狀態?
我知道下面的代碼帶給我的用戶信息...
[facebook requestWithGraphPath:@"me" andDelegate:self];
,但它在哪裏去了?我怎麼能說,獲得用戶的名字或地位,並將其設置爲標籤的價值?
如果有人在回答中給我寫了整個代碼,我會感激gazillion次。
因爲我不是專家的編碼器,所以我很難使用Facebook iOS SDK參考。我只是有這個簡單的問題。Facebook iOS SDK:如何獲取用戶的Facebook狀態?
我知道下面的代碼帶給我的用戶信息...
[facebook requestWithGraphPath:@"me" andDelegate:self];
,但它在哪裏去了?我怎麼能說,獲得用戶的名字或地位,並將其設置爲標籤的價值?
如果有人在回答中給我寫了整個代碼,我會感激gazillion次。
當你調用這個方法,這裏的SDK所期待的:
下面是一個簡單的代碼示例:
---- MyClass.h BEGIN ----
#import <UIKit/UIKit.h>
#import "FBConnect.h"
@interface MyClass : NSObject <FBSessionDelegate, FBRequestDelegate>
@property (nonatomic, retain) Facebook *facebook;
@property (nonatomic, retain) NSString *userStatus;
@end
---- MyClass.h END ----
---- MyClass.m BEGIN ----
#import "MyClass.h"
@implementation MyClass
@synthesize facebook;
@synthesize userStatus;
- (id)init {
self = [super init];
if (self) {
facebook = [[Facebook alloc] initWithAppId:@"App ID Here" andDelegate:self];
}
return self;
}
- (void)fbDidLogin {
NSLog(@"Facebook logged in!");
[facebook requestWithGraphPath:@"me" andDelegate:self];
}
- (void)request:(FBRequest *)request didLoad:(id)result {
NSLog(@"Request loaded! Result: %@", result);
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *jsonResponse = [parser objectWithString:result error:nil];
userStatus = [jsonResponse objectForKey:message];
[parser release];
NSLog(@"User's status message: %@", userStatus);
}
@end
---- MyClass.m END ----
希望這有助於!
Umair,
獲得訪問令牌,你可以使用此代碼後:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://graph.facebook.com/me?access_token=youracesstoken"]];
NSError *err = nil;
NSURLResponse *resp = nil;
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:&resp error:&err];
if (resp != nil) {
NSString *stringResponse = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
NSLog(@"stringResponse---%@",stringResponse);
// stringResponse will be in JSON Format you need to use a JSON parser (Like SBJSON or TouchJSON)
}
你是否還在尋找一個解決方案? – 2012-02-02 19:59:08