2012-07-03 6 views
14

मैंने अपने आवेदन में आईओएस 5 ट्विटर एकीकृत किया है। मैं ट्विटर और लेखा ढांचे के एकीकरण के साथ TWTweetComposeViewController द्वारा ट्वीट्स भेजने में सक्षम हूं।आईओएस 5 में रिवर्ट, उत्तर और पसंदीदा, खाता ढांचे के साथ ट्विटर

अब मैं लेखा ढांचे की सहायता से आईओएस 5 में पुनः ट्वीट, उत्तर और पसंदीदा करना चाहता हूं।

उत्तर

18

रीटविंग के लिए निम्नलिखित कोड का उपयोग करें।

- (void)_retweetMessage:(TwitterMessage *)message 
{ 
    NSString *retweetString = [NSString stringWithFormat:@"http://api.twitter.com/1/statuses/retweet/%@.json", message.identifier]; 
    NSURL *retweetURL = [NSURL URLWithString:retweetString]; 
    TWRequest *request = [[TWRequest alloc] initWithURL:retweetURL parameters:nil requestMethod:TWRequestMethodPOST]; 
    request.account = _usedAccount; 

    [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { 
     if (responseData) 
     { 
      NSError *parseError = nil; 
      id json = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&parseError]; 

      if (!json) 
      { 
       NSLog(@"Parse Error: %@", parseError); 
      } 
      else 
      { 
       NSLog(@"%@", json); 
      } 
     } 
     else 
     { 
      NSLog(@"Request Error: %@", [error localizedDescription]); 
     } 
    }]; 
} 

Taken From Here

गुड लक।

+0

क्या इससे मदद मिली? –

+1

हाँ, धन्यवाद, यह रीटविट के लिए काम करता है, अब मैं पसंदीदा के लिए प्रयास कर रहा हूं और – PJR

+0

उत्तर दे रहा हूं, मैं आपके जवाब को बदनाम कर दूंगा, मैंने इसे पहले ही वोट दिया है, लेकिन मैं पसंदीदा और उत्तर देने की कोशिश कर रहा हूं, इसलिए मैं इंतज़ार कर रहा हूं। :) – PJR

1

ट्वीट्स, रीट्वीट, उत्तर और पसंदीदा तक पहुंचने के लिए TWTweetComposeViewController के बजाय TWRequest कक्षा का उपयोग करें। अधिक जानकारी के लिए इन लिंक का उपयोग करें। Link1 और Link2

+0

धन्यवाद delegate की जगह है , लेकिन कौन से यूआरएल और पैरामीटर मुझे रिटweet, उत्तर और पसंदीदा के लिए पास करना होगा? – PJR

+0

@PJR मेरा जवाब जांचें। –

9

मित्र Jennis के जवाब मुझे मेरे समाधान और जवाब खोजने के लिए मदद करता है:

1) रीट्वीट और पसंदीदा

यह अनुरोध भेजने के लिए एक वर्ग तरीका है के लिए, आप विभिन्न पारित करने के लिए है यूआरएल रीटविट और पसंदीदा के लिए है। रीट्वीट लिए

+ (void)makeRequestsWithURL: (NSURL *)url { 
    // Create an account store object. 
    ACAccountStore *accountStore = [[ACAccountStore alloc] init]; 

    // Create an account type that ensures Twitter accounts are retrieved. 
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; 

    // Request access from the user to use their Twitter accounts. 
    [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) { 
     if(granted) { 
      // Get the list of Twitter accounts. 
      NSArray *accountsArray = [accountStore accountsWithAccountType:accountType]; 

      // For the sake of brevity, we'll assume there is only one Twitter account present. 
      // You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present. 
      if ([accountsArray count] > 0) { 
       // Grab the initial Twitter account to tweet from. 
       ACAccount *twitterAccount = [accountsArray objectAtIndex:0]; 


       // Create a request, which in this example, posts a tweet to the user's timeline. 
       // This example uses version 1 of the Twitter API. 
       // This may need to be changed to whichever version is currently appropriate. 
       TWRequest *postRequest = [[TWRequest alloc] initWithURL:url parameters:nil requestMethod:TWRequestMethodPOST]; 

       // Set the account used to post the tweet. 
       [postRequest setAccount:twitterAccount]; 

       // Perform the request created above and create a handler block to handle the response. 
       [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { 
        NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]]; 
        iOS5Twitter *twitter5 = [[iOS5Twitter alloc] init]; 
        [twitter5 performSelectorOnMainThread:@selector(displayText:) withObject:output waitUntilDone:NO]; 
        [twitter5 release];    }]; 
      } 
     } 

    }]; 

} 

यूआरएल: पसंदीदा के लिए
https://api.twitter.com/1/statuses/retweet/id_str.json.xml
यूआरएल:
https://api.twitter.com/1/favorites/create/id_str.json
https://api.twitter.com/1/favorites/destroy/id_str.json

2) उत्तर

012 के लिए कोड
 + (void)makeRequestForReplyWithSelectedFeed:(NSString *)status inReply2:(NSString *)updateID{ 
    // Create an account store object. 
    ACAccountStore *accountStore = [[ACAccountStore alloc] init]; 

    // Create an account type that ensures Twitter accounts are retrieved. 
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; 



    NSString *trimmedText = status; 
    if ([trimmedText length] > 140.0) { 
     trimmedText = [trimmedText substringToIndex:140]; 
    } 

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0]; 
    [params setObject:trimmedText forKey:@"status"]; 
    if (updateID > 0) { 
     [params setObject:[NSString stringWithFormat:@"%@", updateID] forKey:@"in_reply_to_status_id"]; 
    } 

    // Request access from the user to use their Twitter accounts. 
    [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) { 
     if(granted) { 
      // Get the list of Twitter accounts. 
      NSArray *accountsArray = [accountStore accountsWithAccountType:accountType]; 

      // For the sake of brevity, we'll assume there is only one Twitter account present. 
      // You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present. 
      if ([accountsArray count] > 0) { 
       // Grab the initial Twitter account to tweet from. 
       ACAccount *twitterAccount = [accountsArray objectAtIndex:0]; 


       // Create a request, which in this example, posts a tweet to the user's timeline. 
       // This example uses version 1 of the Twitter API. 
       // This may need to be changed to whichever version is currently appropriate. 
        TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"http://api.twitter.com/1/statuses/update.json"] parameters:params requestMethod:TWRequestMethodPOST]; 

       // Set the account used to post the tweet. 
       [postRequest setAccount:twitterAccount]; 

       // Perform the request created above and create a handler block to handle the response. 
       [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { 
        NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]]; 
        iOS5Twitter *twitter5 = [[iOS5Twitter alloc] init]; 
        [twitter5 performSelectorOnMainThread:@selector(displayText:) withObject:output waitUntilDone:NO]; 
        [twitter5 release];    }]; 
      } 
     } 
    }]; 
} 

विधि कॉल:

[iOS5Twitter makeRequestForReplyWithSelectedFeed:[NSString stringWithFormat:@"%@", tweetMessage.text ]inReply2:[ NSString stringWithFormat:@"%@",selectedFeed.id_str]];

मैं एक वर्ग iOS5Twitter बनाया है और एक वर्ग विधि को लागू, अगर आप अपने नियंत्रक में यह करना चाहते हैं, कृपया द्वारा self

+0

हाय पीजेआर .. मुझे 'कोड = 34 मिल रहा है; संदेश = "क्षमा करें, वह पृष्ठ मौजूद नहीं है"; * https://api.twitter.com/1/favorites/create/id_str.json url पास करते समय। क्या आप कृपया ऐसा करने में मेरी मदद कर सकते हैं? –

+0

@ShahPaneri यह पुस्तकालय में परिवर्तन का मुद्दा हो सकता है।मुझे लगता है कि अब एक दिन ट्विटर ने अपनी लाइब्रेरी बदल दी है, इसलिए इसे देखो, यह आपकी मदद कर सकता है। – PJR

+0

मुझे समस्या मिली। मैंने उपयोगकर्ता को प्रमाणीकृत नहीं किया है, इसलिए यह मुझे त्रुटि दे रहा था। B.T.W. उत्तर के लिए धन्यवाद। :) –

संबंधित मुद्दे