2012-08-29 152 views
0

我想讓我的應用程序與Facebook進行交互。我正在使用他們的Facebook iOS SDK(3.0)和Xcode 4.2。到目前爲止,我實現了一個登錄方法,該方法還要求爲我的應用程序提供適當的 權限。當我從視圖控制器中點擊一個按鈕時,該方法被調用,該方法位於應用程序委託中。現在我想要登錄後將照片發佈到用戶牆上;該按鈕所在的視圖控制器是一個照片查看器,因此我手頭上有圖像。我遇到的問題是,我看到將圖像發佈到牆上的每種方法都包括在應用程序委託中使用Facebook類型對象。爲了做到這一點,你需要導入Facebook.h,這已被棄用,並且手動將其添加到項目中,這樣可以導入導致很多錯誤。 那麼我該如何做到這一點?你如何用棄用的頭文件聲明這個Facebook對象?或者你可以在沒有新SDK中的Facebook對象的情況下做到這一點?從iOS應用程序發佈圖像到用戶的Facebook牆


好的。所以我部分解決了這個問題:

 - (void)facebookButtonHit:(id)sender{ 
    DrillDownAppAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; 
     [appDelegate openSessionWithAllowLoginUI:YES]; 
    if(FBSessionStateOpen){ NSString *[email protected]""; 
    NSString *[email protected]""; 
     //seteaza link-ul postului 
    if([self.optiune isEqualToString:@"SETURI TEMATICE"]){ 
     [email protected]"http://www.calinevents.com/seturi.html";} 
     [email protected]"SET TEMATIC CALIN EVENTS MODEL "; 
     NSInteger i=_pageIndex+1; 
     NSString *mno=[NSString stringWithFormat:@"%i",i]; 
     captt= [captt stringByAppendingString:mno]; 
     //seteaza parametrii postului 
    NSString *Path1 = [[NSBundle mainBundle] bundlePath]; 
    NSString *Datele1 = [Path1 stringByAppendingPathComponent:@"Seturi.plist"]; 
    NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:Datele1]; 
    NSDictionary *tempdicty=[[tempDict objectForKey:@"Rows"] objectAtIndex:_pageIndex]; 
      NSString *tempurl=[tempdicty objectForKey:@"URL"]; 
    NSMutableDictionary *postParams = [[NSMutableDictionary alloc] initWithObjectsAndKeys: 
    linkul, @"link", 
    tempurl, @"picture", 
    @"Imi place acest produs Calin Events", @"name", 
    captt, @"caption", 
    @"  ",@"description", 
    nil]; 

     //posteaza pe Facebook 
    UIAlertView *incarcare=[[UIAlertView alloc] initWithTitle:@"" 
           message:@"Se publica imaginea...\nVa rugam asteptati" 
           delegate:self 
         cancelButtonTitle:nil 
         otherButtonTitles:nil]; 
    [incarcare setBackgroundColor:[UIColor blackColor]]; 
    [incarcare show]; 
    [FBRequestConnection 
    startWithGraphPath:@"me/feed" 
    parameters:postParams 
    HTTPMethod:@"POST" 
    completionHandler:^(FBRequestConnection *connection, 
         id result, 
         NSError *error) { 
     NSString *alertText; 
     if (error) { 
      alertText = [NSString stringWithFormat: 
          @"S-a produs o eroare!\n Va rugam incercati din nou.", 
          error.domain, error.code]; 
     } else { 
      alertText = [NSString stringWithFormat: 
          @"Imaginea a fost postata cu succes!\n Va multumim!", 
          [result objectForKey:@"id"]]; 
     } 
     // Show the result in an alert 

     [[[UIAlertView alloc] initWithTitle:@"" 
            message:alertText 
            delegate:self 
          cancelButtonTitle:@"OK!" 
          otherButtonTitles:nil] 
      show]; 
     [incarcare dismissWithClickedButtonIndex:0 animated:YES]; 
    }]; 
    } 
} 

但現在我得到以下錯誤。第一次調用這個動作時,它給出一個錯誤代碼= 5,HTTP狀態代碼= 400;下一次該按鈕被擊中時,它會起作用,並且圖像會與所有信息一起正確發佈。下一次按下按鈕時,它會再次輸出錯誤,下一次正確發佈。所以它出現錯誤,發佈,錯誤,發佈等。 我能做些什麼來解決這個問題?

回答

0

我改變了代碼,這的前幾行,現在是OK:

DrillDownAppAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; 
    if(![FBSession.activeSession isOpen]){[appDelegate openSessionWithAllowLoginUI:YES]; 
              } 
    if([FBSession.activeSession isOpen]){[appDelegate openSessionWithAllowLoginUI:NO];} 
相關問題