我正在为iOS应用程序开发一个Twitter Feed View。我找到了TWRequest,它的工作方式和我要找的一模一样。但是:我收到一则通知:"TWRequest已被弃用:在iOS 6.0中首次被弃用“。我应该用什么来代替呢?
发布于 2012-11-11 19:14:58
在iOS 6上,您应该使用Social.framework。它有一个名为SLRequest的类。
它的使用方式与已弃用的TWRequest几乎相同,但您需要指定它是twitter请求,而不是facebook请求。
从iOS 6开始,整个Twitter.framework就被弃用了,因为苹果在iOS 6中加入了脸书和微博(中国的社交网络),他们将所有的社会阶层都归入了新的Social.framework。
注意:您必须指定Twitter/Facebook的服务类型,例如:
SLRequest *aRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:myurl
parameters:myparams];请务必查看documentation。
发布于 2015-01-12 20:35:01
这里是一个完整的代码,可以使用Twitter api将文本+图像上传到您的Twitter帐户
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 !");
}
}];
}
}
}];发布于 2015-02-19 17:36:28
如果您计划通过Twitter集成TwitterKit,以便通过您的自定义twitter应用程序执行tweet,那么这可能对您有所帮助。
https://stackoverflow.com/questions/13330596
复制相似问题