Tôi đã rót qua internet trong nhiều ngày để tìm cách thực hiện điều này.iOS Twitter OAuth đảo ngược
Tôi cần yêu cầu mã thông báo truy cập và bí mật từ twitter để chuyển thông tin này tới máy chủ sẽ xử lý các tweet của người dùng cho ứng dụng của tôi.
Tôi đã được theo liên kết này https://dev.twitter.com/docs/ios/using-reverse-auth
Vấn đề là bước 1. Họ không cung cấp cho bạn một ví dụ về bước 1.
Đây là mã của tôi:
NSURL *url = [NSURL URLWithString:TW_OAUTH_URL_REQUEST_TOKEN];
NSDictionary *parameters = @{TW_X_AUTH_MODE_KEY:TW_X_AUTH_MODE_REVERSE_AUTH};
SLRequest *getTwitterAuth = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:url parameters:parameters];
// Assume that we stored the result of Step 1 into a var 'resultOfStep1'
NSString *S = resultOfStep1;
NSDictionary *step2Params = [[NSMutableDictionary alloc] init];
[step2Params setValue:@"kfLxMJsk7fqIuy8URhleFg" forKey:@"x_reverse_auth_target"];
[step2Params setValue:S forKey:@"x_reverse_auth_parameters"];
NSURL *url2 = [NSURL URLWithString:@"https://api.twitter.com/oauth/access_token"];
SLRequest *stepTwoRequest =
[SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:url2 parameters:step2Params];
// You *MUST* keep the ACAccountStore alive for as long as you need an ACAccount instance
// See WWDC 2011 Session 124 for more info.
self.accountStore = [[ACAccountStore alloc] init];
// We only want to receive Twitter accounts
ACAccountType *twitterType =
[self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Obtain the user's permission to access the store
[self.accountStore requestAccessToAccountsWithType:twitterType
withCompletionHandler:^(BOOL granted, NSError *error) {
if (!granted) {
// handle this scenario gracefully
} else {
// obtain all the local account instances
NSArray *accounts =
[self.accountStore accountsWithAccountType:twitterType];
// for simplicity, we will choose the first account returned - in your app,
// you should ensure that the user chooses the correct Twitter account
// to use with your application. DO NOT FORGET THIS STEP.
[stepTwoRequest setAccount:[accounts objectAtIndex:0]];
// execute the request
[stepTwoRequest performRequestWithHandler:
^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *responseStr =
[[NSString alloc] initWithData:responseData
encoding:NSUTF8StringEncoding];
// see below for an example response
NSLog(@"The user's info for your server:\n%@", responseStr);
}];
}
}];
Tôi đã được cố gắng tìm ra cách tôi xử lý SLRequest trong oder để chuyển nó đến bước 2 từ tài liệu twitter.
Tôi cũng đã sử dụng điều này tại đây: https://github.com/seancook/TWReverseAuthExample
Mã này rất tuyệt vời nhưng rất phức tạp. Mọi sự trợ giúp sẽ rất được trân trọng! Cảm ơn!
nó không làm việc, mặc dù đi vào nếu khối nhưng với giá trị chứng chỉ = " Xml version" = "\" 1.0 \ "encoding = \" UTF-8 \ "?> \ n \ n Thông tin đăng nhập xác thực ngược không hợp lệ \ n \ n"; –
Abhishek
Không làm việc cho tôi nữa, cùng một lỗi –