2012-01-23 11 views
-1

誰もが私のapp.iの目的cを使用してfacebookに写真を投稿するのに役立つことができますが、私はiphone.itsでチェックしたときに終了して、シミュレータで正常に動作しています。フォローするfb.i私のアプリを開発するためにグラフapiを使用してください。iphoneアプリでfacebookに画像を投稿するには?

-(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"]; 
     [self.view addSubview:viewshare]; 
    } 
    else { 
     NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:2]; 

     //imgPicture is my image view name 
     NSLog(@"the Data::%@\n",imgPicture.image); 

     FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:imgPicture.image]; 

     [variables setObject:graph_file forKey:@"file"]; 

     [variables setObject:[NSString stringWithFormat:@"%@", txtComment.text] forKey:@"message"]; 

     FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:@"me/photos" withPostVars:variables]; 
     NSLog(@"postPictureButtonPressed: %@", fb_graph_response.htmlResponse); 

     NSLog(@"Now log into Facebook and look at your profile & photo albums..."); 

     [email protected]" "; 
     [txtComment setHidden:YES]; 
     [lblcmt setHidden:YES]; 
     UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:nil message:@"Successfully posted...Now log into Facebook & look at your profile" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
     [alertView show]; 
     [alertView release]; 
    } 
    [fbGraph release]; 
} 
+0

Xcodeで計測器を使用してアプリを実行しましたか? –

+0

ごめんなさい... – Lpkm

答えて

1

のFacebook(フェイスブックオブジェクト)が有効なセッションを持っている場合、私がチェックまず:

if (![facebook_ isSessionValid]) { 

    permissions_ = [[NSArray arrayWithObjects:@"read_stream", @"publish_stream", @"offline_access",nil] retain]; 
    [facebook_ authorize:permissions_]; 

} 

私は私がログインfacebookにログインしてる保証は私はこのような画像を投稿することができた場合:

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
            image, @"picture", 
            message, @"message", 
            nil]; 

[facebook_ requestWithGraphPath:@"me/photos" 
         andParams:params 
        andHttpMethod:@"POST" 
        andDelegate:self]; 

最後に、私は画像のポストが成功したかどう確かであるために、この方法を確認してください。

-(void)request:(FBRequest *)request didFailWithError:(NSError *)error { 

    //Error 

} 

-(void)request:(FBRequest *)request didLoad:(id)result { 

    //Succes 
} 
関連する問題