मैं एक आईओएस ऐप के लिए एक ट्विटर फ़ीड व्यू विकसित कर रहा हूं। मुझे TWRequest मिला और यह ठीक उसी तरह काम करता है जिसे मैं ढूंढ रहा था। लेकिन: मुझे एक सूचना मिलती है: "TWRequest को बहिष्कृत किया गया है: पहले आईओएस 6.0 में बहिष्कृत"। इसके बजाय मुझे क्या उपयोग करना चाहिए?आईओएस 6.0 में TWRequest को बहिष्कृत किया गया है - मैं इसके बजाय क्या उपयोग कर सकता हूं?
उत्तर
आईओएस 6 पर आपको Social.framework
का उपयोग करना चाहिए। इसमें SLRequest
नाम की एक कक्षा है।
आप इसे लगभग TWRequest
के रूप में उसी तरह उपयोग करते हैं, लेकिन आपको यह निर्दिष्ट करने की आवश्यकता है कि यह फेसबुक अनुरोध के विपरीत एक ट्विटर अनुरोध है।
संपूर्ण Twitter.framework
आईओएस 6 के रूप में बहिष्कृत हो गया, चूंकि ऐप्पल ने आईओएस 6 में फेसबुक और वेबो (एक चीनी सोशल नेटवर्क) जोड़ा, इसलिए उन्होंने सभी सामाजिक वर्गों को नए Social.framework
में समूहीकृत किया।
नोट आप ट्विटर/फेसबुक, उदाहरण के लिए सेवा प्रकार उल्लेख करना होगा:
SLRequest *aRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:myurl
parameters:myparams];
documentation की जाँच करने के लिए सुनिश्चित करें।
यहाँ ट्विटर एपीआई का उपयोग कर अपने ट्विटर खाते में पाठ + छवि अपलोड करने के लिए एक पूर्ण कोड है
UIImage *img = [UIImage imageNamed:@"twitterImage.png"];
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if (granted == YES) {
// Populate array with all available Twitter accounts
NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
if ([arrayOfAccounts count] > 0) {
ACAccount *acct = [arrayOfAccounts objectAtIndex:0];
NSDictionary *message = @{@"status": @"From my app"};
NSURL *requestURL = [NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update_with_media.json"];
SLRequest *postRequest = [SLRequest
requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:requestURL parameters:message];
NSData *data = UIImagePNGRepresentation(img);
[postRequest addMultipartData:data withName:@"media" type:@"image/png" filename:@"TestImage"];
postRequest.account = acct;
[postRequest performRequestWithHandler:
^(NSData *responseData, NSHTTPURLResponse
*urlResponse, NSError *error)
{
if (error) {
NSLog(@"%@",error.description);
}
else {
NSLog(@"Upload Sucess !");
}
}];
}
}
}];
मामले में आप ट्विटर द्वारा TwitterKit को एकीकृत अपने कस्टम चहचहाना अनुप्रयोग के माध्यम से ट्विट्स तो यह प्रदर्शन करने के लिए पर योजना आपकी मदद कर सकता है
एक अन्य विकल्प ट्विटर एपीआई का उपयोग करने के लिए है। इसके लिए आपके पास ट्विटर ढांचा होना चाहिए।
NSString *statusesShowEndpoint = @"https://api.twitter.com/1.1/statuses/update.json";
NSDictionary *params = @{@"status": @"Hello, my first autopost tweet..."};
NSError *clientError;
NSURLRequest *request = [[[Twitter sharedInstance] APIClient]
URLRequestWithMethod:@"POST"
URL:statusesShowEndpoint
parameters:params
error:&clientError];
if (request) {
[[[Twitter sharedInstance] APIClient]
sendTwitterRequest:request
completion:^(NSURLResponse *response,
NSData *data,
NSError *connectionError) {
if (data) {
// handle the response data e.g.
NSError *jsonError;
NSDictionary *dicResponse = [NSJSONSerialization
JSONObjectWithData:data
options:0
error:&jsonError];
NSLog(@"%@",[dicResponse description]);
}
else {
NSLog(@"Error code: %ld | Error description: %@", (long)[connectionError code], [connectionError localizedDescription]);
}
}];
}
else {
NSLog(@"Error: %@", clientError);
}
2015:
तो निम्न कोड कर उपयोग "https://api.twitter.com/1.1/statuses/update.json" और यह भी ध्यान दें कि त्रुटियों काफी संभवतः में JSON के रूप में वापस आ सकते हैं प्रतिक्रिया डेटा। – prewett