Reputation: 571
I am developing an app. I have done Login Using OAuth. Now i want to post an Image to my Twitter Account.But each time i am getting Capacity Over Error message.I tried with Both media and media_data after converting my String into Base64.I am trying with Ionic and Angular JS.You can also suggest me any Other Solution. My code is below.
var clientId = "**************";
var clientSecret = "*****************";
/** Twitter oauth for User Details **/
// Accessing profile info from twitter
var oauthObject = {
oauth_consumer_key: clientId,
oauth_nonce: $cordovaOauthUtility.createNonce(10),
oauth_signature_method: "HMAC-SHA1",
oauth_token: token.oauth_token,
oauth_timestamp: Math.round((new Date()).getTime() / 1000.0),
oauth_version: "1.0"
};
var signatureObj = $cordovaOauthUtility.createSignature("POST", "https://upload.twitter.com/1.1/media/upload.json" , oauthObject, { }, clientSecret, token.oauth_token_secret);
$http.defaults.headers.common.Authorization = signatureObj.authorization_header;
//$http.post(url, {media_data: 'base64'},{headers: { 'Content-Type': 'multipart/form-data'}}).success(function(
$http.post(url, {media: 'Image URL'},{headers: { 'Content-Type': 'multipart/form-data'}}).success(function(result) {
console.log(result)
})
.error(function(result) {
console.log(result)
});
Any Body can help me in this Problem.
Upvotes: 2
Views: 1018
Reputation: 571
I tried these :
https://github.com/saimon24/ng-twitter
https://devdactic.com/twitter-rest-api-angularjs/
I sent Base64 String in Post request.
var MEDIA_UPLOAD_URL = 'https://upload.twitter.com/1.1/media/upload.json';
//A custom function in Twitte Api
postMedia: function (base64Media, parameters) {
return postRequest(MEDIA_UPLOAD_URL, {media: base64Media}, parameters);
},
Upvotes: 1