Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何使用TWRequest更改配置文件图片_Objective C_Ios_Twitter_Twrequest - Fatal编程技术网

Objective c 如何使用TWRequest更改配置文件图片

Objective c 如何使用TWRequest更改配置文件图片,objective-c,ios,twitter,twrequest,Objective C,Ios,Twitter,Twrequest,如何使用TWRequest更改配置文件图片, 我使用此代码发布到timeLine -(IBAction)postToTwitter { ACAccountStore*account=[[ACAccountStore alloc]init]; ACAccountType*accountType=[帐户类型WithAccountTypeIdentifier:ACAccountTypeIdentifierWitter] // Request access from the user to access

如何使用TWRequest更改配置文件图片, 我使用此代码发布到timeLine

-(IBAction)postToTwitter { ACAccountStore*account=[[ACAccountStore alloc]init]; ACAccountType*accountType=[帐户类型WithAccountTypeIdentifier:ACAccountTypeIdentifierWitter]

// Request access from the user to access their Twitter account
[account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) 
 {
     // Did user allow us access?
     if (granted == YES)
     {
         // Populate array with all available Twitter accounts
         NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];

         // Sanity check
         if ([arrayOfAccounts count] > 0) 
         {
             // Keep it simple, use the first account available
             ACAccount *acct = [arrayOfAccounts objectAtIndex:0];

             // Build a twitter request

            //http://api.twitter.com/1/account/update_profile_image.json  
             //https://upload.twitter.com/1/statuses/update_with_media.json

             TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update_with_media.json"] parameters:nil requestMethod:TWRequestMethodPOST];

             //NSData *myData = UIImagePNGRepresentation(self.selectedImage);
            NSData *myData =  UIImageJPEGRepresentation(self.selectedImage, 0.5);

             [postRequest addMultiPartData:myData withName:@"media" type:@"image/jpg"];

             [postRequest setAccount:acct];

             // Block handler to manage the response
             /*      
              [postRequest addMultiPartData:[base64 dataUsingEncoding:NSUTF8StringEncoding] // base64 is an NSString of the encoded image

              withName:@"image"

              type:@"multipart/form-data"];

              // Post the request*/

             [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) 
              {
                  NSLog(@"Twitter response, HTTP response: %i", [urlResponse statusCode]);
              }
              ];


     }
    }
 }];

}

我也很难做到这一点,以苹果公司的WWDC11幻灯片为指导,但从那时起,Twitter似乎已经改变了API(或者幻灯片有bug)

解决方案很简单:您需要使用多部分数据名“image”而不是“media”。我认为类型应该是“image/jpeg”,而不是“image/jpg”

因此,将该行更改如下:

[postRequest addMultiPartData:myData withName:@"image" type:@"image/jpeg"];