2011-11-10 5 views
28

नए आईओएस 5 एपीआई का उपयोग करके ट्विटर पर किसी का अनुसरण "करने" की कोशिश कर रहा है, 406 रिटर्न त्रुटि प्राप्त कर रहा है। क्यूं कर?नए आईओएस 5 एपीआई का उपयोग करके ट्विटर पर किसी को "फ़ॉलो" करने का प्रयास कर, 406 रिटर्न त्रुटि प्राप्त हो रही है। क्यूं कर?

क्या मेरा कोड सही है? यह पता लगाने की आवश्यकता है कि यह क्यों काम नहीं कर रहा है ....

- (void)followOnTwitter:(id)sender 
{ 
    ACAccountStore *accountStore = [[ACAccountStore alloc] init]; 

ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; 

[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]; 

      NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init]; 
      [tempDict setValue:@"sortitapps" forKey:@"screen_name"]; 
      [tempDict setValue:@"true" forKey:@"follow"]; 

      TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"http://api.twitter.com/1/friendships/create.format"] 
                 parameters:tempDict 
                 requestMethod:TWRequestMethodPOST]; 


      [postRequest setAccount:twitterAccount]; 

      [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { 
       NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]]; 
       NSLog(@"%@", output); 

       }]; 
      } 
     } 
    }]; 
} 

सभी कोड सही दिखते हैं। क्या पैरामीटर गलत हैं? क्या यूआरएल सही है? यहां कुछ दिशा की आवश्यकता है ....

+0

के रूप में समझाने के लिए नीचे का उपयोग कर सकते, त्रुटि गलत URL जो 'होना चाहिए' 'http से आता है। '/' http: // api.twitter.com/1/दोस्ती/create.format''' – Martin

+0

के बजाय कॉम/1/दोस्ती/create.json''' जैसा कि नीचे बताया गया है, यह https नहीं है http इसलिए उपर्युक्त टिप्पणी गलत है –

उत्तर

20

मेरे अपने प्रश्न का उत्तर मिला ... मैंने URL को https://api.twitter.com/1/friendships/create.json पर बदल दिया और यह काम किया।

यह http नहीं है, न केवल http।

+0

यह मेरे लिए तब तक काम नहीं कर रहा जब तक कि मैंने https: // infront जोड़ा यूआरएल –

+0

बस ध्यान दिया कि यह मूल रूप से था, त्वरित नोट ताकि आप यूआरएल के साथ प्रतिस्थापित न हों और उस भाग को छोड़ दें। आप स्पष्टता के लिए उत्तर संपादित करना चाह सकते हैं। महान काम करता है, धन्यवाद। –

20

आईओएस 6 के लिए चहचहाना अब नीचे दिया यूआरएल उपयोग

ACAccountStore *accountStore = [[ACAccountStore alloc] init]; 

ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; 

[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(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]; 

      NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init]; 
      [tempDict setValue:@"MohammadMasudRa" forKey:@"screen_name"]; 
      [tempDict setValue:@"true" forKey:@"follow"]; 
      NSLog(@"*******tempDict %@*******",tempDict); 

      //requestForServiceType 

      SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:[NSURL URLWithString:@"https://api.twitter.com/1/friendships/create.json"] parameters:tempDict]; 
      [postRequest setAccount:twitterAccount]; 
      [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { 
       NSString *output = [NSString stringWithFormat:@"HTTP response status: %i Error %d", [urlResponse statusCode],error.code]; 
       NSLog(@"%@error %@", output,error.description); 
      }]; 
     } 

    } 
}]; 
+0

अच्छा एक अमित, धन्यवाद! –

+0

उत्तर अमित के लिए धन्यवाद। त्वरित स्पष्टीकरण - क्या ट्विटर के साथ पहले प्रमाणीकरण की आवश्यकता है? – Prasanth

2

चहचहाना v1.1 करने के लिए अपने एपीआई को अपडेट किया गया के रूप में, अनुरोध किया जाना चाहिए का पालन करें। ध्यान दें कि अनुरोध 'https: //' के साथ होना चाहिए और API v1.1 के कारण आपके यूआरएल में 1 से 1.1 को प्रतिस्थापित करें। //api.twitter:

https://api.twitter.com/1.1/friendships/create.json

+0

उपरोक्त यूआरएल आईओएस 6 और उसके बाद के लिए अनुशंसित है। –

1

आप इस कोड

- (BOOL)openTwitterClientForUserName:(NSString*)userName { 
NSArray *urls = [NSArray arrayWithObjects: 
       @"twitter://user?screen_name={username}", // Twitter 
       @"tweetbot:///user_profile/{username}", // TweetBot 
       @"echofon:///user_timeline?{username}", // Echofon    
       @"twit:///user?screen_name={username}", // Twittelator Pro 
       @"x-seesmic://twitter_profile?twitter_screen_name={username}", // Seesmic 
       @"x-birdfeed://user?screen_name={username}", // Birdfeed 
       @"tweetings:///user?screen_name={username}", // Tweetings 
       @"simplytweet:?link=http://twitter.com/{username}", // SimplyTweet 
       @"icebird://user?screen_name={username}", // IceBird 
       @"fluttr://user/{username}", // Fluttr 
       /** uncomment if you don't have a special handling for no registered twitter clients */ 
       //@"http://twitter.com/{username}", // Web fallback, 
       nil]; 

UIApplication *application = [UIApplication sharedApplication]; 
for (NSString *urlString in urls) { 
    NSString *candidate = [urlString stringByReplacingOccurrencesOfString:@"{username}" withString:userName]; 
    NSURL *url = [NSURL URLWithString:candidate]; 
    if ([application canOpenURL:url]) { 
     [application openURL:url]; 
     return YES; 
    } 
} 
return NO; 
} 

https://gist.github.com/ChrisRicca/9144169

+0

हालांकि यह लिंक प्रश्न का उत्तर दे सकता है, लेकिन यहां उत्तर के आवश्यक हिस्सों को शामिल करना बेहतर है और संदर्भ के लिए लिंक प्रदान करना बेहतर है। लिंक किए गए पृष्ठ में परिवर्तन होने पर लिंक-केवल उत्तर अमान्य हो सकते हैं। –

+0

धन्यवाद – SyraKozZ

+0

इस कोड को काम करने के लिए आपको अपनी 'info.plist' फ़ाइल को संपादित करना होगा और यूआरएल उपसर्गों को एक सरणी में प्रविष्टियों के रूप में जोड़ें:' LSApplicationQueriesSchemes'। –

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