ACAccountStore Twitter 凭据
ACAccountStore Twitter credentials
我有一个问题,ACAccountStore 是否会自动更新 Twitter 令牌?我需要令牌才能在我的服务器中用于自动发布。请分享您的经验。
如果你post像这样使用 SLRequest 你应该没有问题(self.account
是你从 ACAccountStore 中检索到的 Twitter ACaccount):
/**
* Post a status update via the account
*
* @param NSString* status status to post
*/
- (void)postViaAccountWithStatus:(NSString *)status
{
// Create the parameters dictionary and the URL (!use HTTPS!)
NSDictionary *parameters = @{@"status": status };
NSURL *URL = [NSURL URLWithString:kTwitterStatusesUpdateEndpoint];
// Create request
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:URL
parameters:parameters];
// Since we are performing a method that requires authorization we can simply
// add the ACAccount to the SLRequest
[request setAccount:self.account];
// Perform request
[request performRequestWithHandler:^(NSData *respData, NSHTTPURLResponse *urlResp, NSError *error)
{
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:respData
options:kNilOptions
error:&error];
// Check for errors in the responseDictionary
if ( urlResp.statusCode == 200 )
[self updateStatusCompleteWithStatus:SHUpdateSuccessful error:error];
else
[self updateStatusCompleteWithStatus:SHUpdateFailed error:error];
}];
}
我有一个问题,ACAccountStore 是否会自动更新 Twitter 令牌?我需要令牌才能在我的服务器中用于自动发布。请分享您的经验。
如果你post像这样使用 SLRequest 你应该没有问题(self.account
是你从 ACAccountStore 中检索到的 Twitter ACaccount):
/**
* Post a status update via the account
*
* @param NSString* status status to post
*/
- (void)postViaAccountWithStatus:(NSString *)status
{
// Create the parameters dictionary and the URL (!use HTTPS!)
NSDictionary *parameters = @{@"status": status };
NSURL *URL = [NSURL URLWithString:kTwitterStatusesUpdateEndpoint];
// Create request
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:URL
parameters:parameters];
// Since we are performing a method that requires authorization we can simply
// add the ACAccount to the SLRequest
[request setAccount:self.account];
// Perform request
[request performRequestWithHandler:^(NSData *respData, NSHTTPURLResponse *urlResp, NSError *error)
{
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:respData
options:kNilOptions
error:&error];
// Check for errors in the responseDictionary
if ( urlResp.statusCode == 200 )
[self updateStatusCompleteWithStatus:SHUpdateSuccessful error:error];
else
[self updateStatusCompleteWithStatus:SHUpdateFailed error:error];
}];
}