Graph Api を使用して、アプリケーションに facebook を実装できます。
Graph api のオブジェクトを作成し、NSString *client_id = @"124262614407976"; のようにパーミッションを設定します。
if(到達可能性フラグ==TRUE) {
@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" andSuperView:self.window];
}
@catch (NSException *例外) {
// NSLog(@"Net not available %@",exception.userInfo); } @最後に {
}
}
-- コールバックを確認した後。- (void)fbGraphCallback:(id)送信者 {
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 {
}
}
}