我已经在互联网上倾倒了几天,试图弄清楚如何实现这一点.
我需要从twitter请求访问令牌和秘密,以便将其传递给将为我的应用程序处理用户推文的服务器.
我一直关注此链接https://dev.twitter.com/docs/ios/using-reverse-auth
问题是第1步.他们没有给你一个步骤1的例子.
这是我的代码:
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 …Run Code Online (Sandbox Code Playgroud) 我正在使用Twitter的SLRequest,直到几天前一切正常,下面的代码,但现在响应是空的,错误描述为空,这是我总是使用的代码:
ACAccountStore *accountStoreTw = [[ACAccountStore alloc] init];
ACAccountType *accountTypeTw = [accountStoreTw accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStoreTw requestAccessToAccountsWithType:accountTypeTw options:NULL completion:^(BOOL granted, NSError *error) {
if(granted) {
FMDatabase *db = [FMDatabase databaseWithPath:[self databasePath]];
if ([db open]) {
FMResultSet *tw_name_q = [db executeQuery:@"SELECT tw_username FROM settings WHERE id = 1"];
NSString *tw_name = @"";
while ([tw_name_q next]) {
tw_name = [tw_name_q stringForColumn:@"tw_username"];
}
if (![tw_name isEqualToString:@""]) {
NSArray *accountsArray = [accountStoreTw accountsWithAccountType:accountTypeTw];
for (ACAccount *tw_account in accountsArray) {
if ([[tw_account username] isEqualToString:tw_name]) {
SLRequest* twitterRequest = …Run Code Online (Sandbox Code Playgroud) 我需要使用SLrequest访问Direct Messages.我使用Twitter的Reverse oAuth获得了oAuthToken和oAuthToken Secret.现在,我需要知道如何从https://api.twitter.com/1.1/direct_messages.json网址获取直接消息.我已经尝试添加oAuthToken和oAuthTokenSecret部分SLRequest,但我得到相同的错误,"此应用程序不允许访问或删除您的直接消息".oAuthToken和oAuthTokenSecret有什么用?如何让直接消息适用于应用程序?我已将应用程序的访问级别更改为"读取,写入和直接消息".请帮我解决问题.
有没有办法使用iOS社交/帐户框架从Twitter获取用户数据(名字,姓氏和电子邮件)?我可以用Facebook做到这一点,但我对Twitter做的每一个SLRequest都返回一个空数组.
这是我现在的代码.我尝试了几个不同参数的URL,但我没有运气.
- (void)populateTwitterAccount {
NSURL *twitterURL = [NSURL URLWithString:@"https://api.twitbridge.com/1.1/users/show.json"];
SLRequest *twitterRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:twitterURL parameters:nil];
[twitterRequest setAccount:self.twitterAccount];
[twitterRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *accountDataString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"%@", accountDataString);
}];
Run Code Online (Sandbox Code Playgroud)
}
我有一个问题,我有一些粉丝,我想发送一个带有图像的直接消息给所有粉丝,但我没有办法做到这一点.
我研究整个文档但无法找到方法.
我的代码在这里:
NSString *strUrl = @"https://api.twitter.com/1.1/direct_messages/new.json";
NSURL *url = [NSURL URLWithString:strUrl];
strUrl = nil;
NSMutableDictionary *parameters = [NSMutableDictionary new];
[parameters setValue:@"name" forKey:@"screen_name"];
[parameters setValue:@"123456" forKey:@"user_id"];
[parameters setValue:@"sending text" forKey:@"text"];
// Creating a request.
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:url
parameters:parameters];
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.greenuplawnandsprinklers.com/uploads/design_sample_landscape.jpg"]];
[request addMultipartData:imageData
withName:@"media[]"
type:@"image/jpeg"
filename:@"image.jpg"];
imageData = nil;
[request setAccount:twitAccount];
url = nil;
parameters = nil;
// Perform the request.
[request performRequestWithHandler:^(NSData *responseData,NSHTTPURLResponse *urlResponse,NSError *error)
{
dispatch_async(dispatch_get_main_queue(), ^{
// Check if we …Run Code Online (Sandbox Code Playgroud) 我想使用我的AppID在facebook上分享我的图像.所以我可以在facebook上看到它via App.它工作正常,直到iOS 5.但不是在iOS 6.
如果我正在使用SLComposeViewController,那么我可以共享图像,但显示"通过iOS"而不是"通过应用程序".所以我已经审查了它的代码并应用了,但它没有共享图像.请检查代码是否有任何问题并予以纠正.
facebookaccount = [[ACAccountStore alloc] init];
ACAccountType *facebookaccountType = [facebookaccount accountTypeWithAccountTypeIdentifier: ACAccountTypeIdentifierFacebook];
// Specify App ID and permissions
NSDictionary *options = @{ ACFacebookAppIdKey: @"xxxxxxxxxxxxx", ACFacebookPermissionsKey: @[@"publish_stream"], ACFacebookAudienceKey: ACFacebookAudienceFriends };
[facebookaccount requestAccessToAccountsWithType:facebookaccountType options:options completion:^(BOOL granted, NSError *error) {
if (granted) {
NSArray *accountsArray = [facebookaccount accountsWithAccountType:facebookaccountType];
facebookAccount = [[accountsArray lastObject] retain];
NSLog(@" Account :::: %@", facebookAccount);
} else {
NSLog(@" Error :::: %@", error.description);
}}];
NSDictionary *parameters = @{@"message" : @""};
NSString *link …Run Code Online (Sandbox Code Playgroud)