Oleg Gordiichuk
Oleg Gordiichuk

Reputation: 15512

ACAccountStore Twitter credentials

I have a question if ACAccountStore automatically update Twitter token? I need token to use in in my server for auto posting. Please share you're experience.

Upvotes: 0

Views: 85

Answers (1)

Larry Borsato
Larry Borsato

Reputation: 394

If you post using SLRequest like this you should have no issues (self.account is the Twitter ACAccount you retrieved from the ACAccountStore):

/**
 *  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];

    }];
}

Upvotes: 1

Related Questions