您可以通过使用 Graph Api 在您的应用程序中实现 facebook。
创建 Graph api 对象并设置权限,如 NSString *client_id = @"124262614407976";
如果(可达性标志==真){
@try {
self.fbGraph = [[FbGraph alloc] initWithFbClientID:client_id];
[self.fbGraph authenticateUserWithCallbackObject:self
andSelector:@selector(fbGraphCallback:) andExtendedPermissions:@"user_photos,user_videos,
publish_stream,offline_access,user_checkins,friends_checkins" and SuperView:self.window];
}
@catch (NSException *异常) {
// NSLog(@"网络不可用 %@",exception.userInfo); } @最后 {
}
}
-- 检查后回调。- (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....");
//restart the authentication process.....
[fbGraph authenticateUserWithCallbackObject:self andSelector:@selector(fbGraphCallback:)
andExtendedPermissions:@"user_photos,user_videos,publish_stream,offline_access,user_checkins,friends_checkins"];
} else
{
// NSLog(@"------------>CONGRATULATIONS<------------, You're logged into Facebook... Your oAuth token is: %@", fbGraph.accessToken);
}
}
//////// 你可以找到朋友提要..
-(void)getMeFeedButtonPressed{
if(delegate.fbGraph.accessToken!=nil)
{
NSString *customString=[NSString stringWithFormat:@"me"];
NSLog(@"here responce is for %@",customString);
FbGraphResponse *fb_graph_response = [delegate.fbGraph doGraphGet:customString withGetVars:nil];
NSLog(@"getMeFeedButtonPressed: %@", fb_graph_response.htmlResponse);
//parse our json
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *facebook_response = [parser objectWithString:fb_graph_response.htmlResponse error:nil];
// [facebook_response ]
[parser release];
// MyID=[facebook_response objectForKey:@"id"] ;
[MyID appendString:[facebook_response objectForKey:@"id"]];
NSLog(@"name %@",[facebook_response objectForKey:@"name"]);
NSString * url = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture",MyID];
NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
UIImage *downloadedImage = [UIImage imageWithData:data];
NSData *myEncodedImages = [NSKeyedArchiver archivedDataWithRootObject:downloadedImage];
[[NSUserDefaults standardUserDefaults ] setObject:myEncodedImages forKey:@"MYFBIMAGE"];
[self postData];
}else
{
@try {
[delegate.fbGraph authenticateUserWithCallbackObject:self andSelector:@selector(fbGraphCallback:)
andExtendedPermissions:@"user_photos,user_videos,publish_stream,offline_access,user_checkins,friends_checkins,email"];
}
@catch (NSException *exception) {
NSLog(@"Net not available");
}
@finally {
}
}
}