2014-11-17 35 views
0

我在這裏很難過。在我的應用程序中有一部分是STTwitter成功的,還有另一部分(使用相同的代碼)不會返回任何內容。 `STTwitter不返回任何成功或錯誤

-(IBAction)followTwitter:(id)sender { 

if ([[NSUserDefaults standardUserDefaults] objectForKey:@"twitter_on_file" ] == nil) { 

    UIAlertView *allert = [[UIAlertView alloc] initWithTitle:@"Uh oh!" message:@"You have not linked your twitter account quite yet! Head to My Account settins to do so." delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil]; 
    [allert show]; 

} else { 
    ACAccountStore *store1 = [[ACAccountStore alloc] init]; 
    ACAccountType *twitterAccountType = [store1 accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; 
    if ([twitterAccountType accessGranted]) { 
     [store1 requestAccessToAccountsWithType:twitterAccountType options:nil completion:^(BOOL granted, NSError *error) { 

      arrayOfUsernames = [[NSMutableArray alloc] init]; 

      iosAccounts = [store1 accountsWithAccountType:twitterAccountType]; 
      for (ACAccount *accou in iosAccounts) { 
       [arrayOfUsernames addObject:accou.username]; 
      } 

      NSString *usernameOnFile = [[NSUserDefaults standardUserDefaults] objectForKey:@"twitter_on_file" ]; 
      int tracker = 0; 

      for (NSString *username in arrayOfUsernames) { 

       if ([username isEqualToString:usernameOnFile]) { 
        NSLog(@"Using twitter account: %@", username); 
        STTwitterAPI *twitterAPI = [STTwitterAPI twitterAPIOSWithAccount:iosAccounts[tracker]]; 
        [twitterAPI verifyCredentialsWithSuccessBlock:^(NSString *username) { 
         NSLog(@"Successfully authenticated the user"); 

        } errorBlock:^(NSError *error) { 

         NSLog(@"Erorr: %@", error); 

        }]; 
        NSLog(@"Twitter API: %@", twitterAPI); 

        [twitterAPI postFriendshipsCreateForScreenName:@"kickscaterer" orUserID:nil successBlock:^(NSDictionary *befriendedUser) { 

         NSLog(@"Befriend %@", befriendedUser); 


        } errorBlock:^(NSError *error) { 

         NSLog(@"Error: %@", error); 
        }]; 
       } else { 
        tracker++; 
       } 
      } 
     }]; 
    } 
} 

} `

,做工作的一部分:

STTwitterAPI *twitter= [STTwitterAPI twitterAPIOSWithAccount:iosAccounts[indexForAlert.row]]; 

     [twitter verifyCredentialsWithSuccessBlock:^(NSString *username) { 
      // ... 
      NSLog(@"Username: %@", username); 
      // [self.tableView reloadData]; 


      [[NSUserDefaults standardUserDefaults] setObject:twitter.userName forKey:@"twitter_on_file"]; 

     } errorBlock:^(NSError *error) { 
      NSLog(@"Error: %@", error); 
      // ... 
     }]; 

     [twitter postFriendshipsCreateForScreenName:@"didi4" orUserID:nil successBlock:^(NSDictionary *befriendedUser) { 

      NSLog(@"Befriend %@", befriendedUser); 


     } errorBlock:^(NSError *error) { 

      NSLog(@"Error: %@", error); 
     }]; 

感謝

不工作的一部分!

回答

0

postFriendshipsCreateForScreenName:方法應該叫做裏面的成功塊,在同一級別比日誌「成功驗證用戶」。

+0

非常感謝您的回覆!我試過這個,但它仍然沒有工作。 – user2918201

+0

等待我想我找到了問題。 – user2918201

+0

好的,所以現在它確實會返回一些東西,謝謝你。但是,它返回一個錯誤:您的憑據不允許訪問此資源。考慮到我在設置中使用本地iOS帳戶,這很奇怪。 – user2918201

相關問題