2012-01-23 57 views
-1

任何人都可以請求幫助我發佈在Facebook上使用目標c iPhone應用程序的照片.i試過但它的終止當我檢查與iphone.its工作正常在simulator.following是我的代碼,我曾經發布在fb.i使用圖形API來開發我的應用程序。如何在iphone應用程序中發佈圖片?

-(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(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 
} 
相關問題