ios - 通过 oauth 将图像发送到 Twitter
<p><p>我可以使用 oauth 成功登录 Twitter。现在我需要发布带有状态的图像。为此,我实现了以下..</p>
<pre><code>-(void)shareontw{
NSString *postUrl =@"https://api.twitter.com/1.1/statuses/update_with_media.json";
NSMutableURLRequest *req = ];
forHTTPHeaderField:@"Authorization"];
;
NSString *boundary = @"0xKhTmLbOuNdArY---This_Is_ThE_BoUnDaRyy---pqo";
NSString *headerBoundary = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",
boundary];
;
NSMutableData *myRequestData = ;
NSData *imageData = UIImageJPEGRepresentation(globalimage, 0.8);
dataUsingEncoding:NSUTF8StringEncoding]];
];
];
];
// add it to body
;
];
dataUsingEncoding:NSUTF8StringEncoding]];
];
];
];
dataUsingEncoding:NSUTF8StringEncoding]];
;
NSHTTPURLResponse *response;
NSError *error = nil;
NSString *responseString = [[ initWithData: encoding:NSUTF8StringEncoding] autorelease];
if (error) {
NSLog(@"Error from NSURLConnection: %@", error);
}
NSLog(@"Got HTTP status code from Twitter after posting profile image: %d", );
NSLog(@"Response string: %@", responseString);}
</code></pre>
<p>但它给了我错误:响应字符串:{"errors":[{"message":"Bad Authentication data","code":215}]}</p>
<p>我无法找到我在这里做错的问题。如果有人有想法,请帮助我。</p>
<p>提前致谢。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>感谢您上面的代码运行良好,为我节省了很多时间。我只需更改一行代码</p>
<p>这一行 NSData *imageData = UIImageJPEGRepresentation(globalimage, 0.8);</p>
<p>替换为</p>
<p>NSData *imageData = UIImageJPEGRepresentation(_imgView.image, 0.8);</p>
<p>它正在工作:)</p></p>
<p style="font-size: 20px;">关于ios - 通过 oauth 将图像发送到 Twitter,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/20042700/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/20042700/
</a>
</p>
页:
[1]