When attempting to update or post a status on Twitter using Ionic, I encounter an issue. The OAuth authentication works successfully for retrieving the UserProfile Api. However, when trying to post an image or status, an error is displayed ("Could not authenticate you"). Below is my code snippet:
var services = angular.module('twitter.service', [])
services.factory('TwitterLoginFactory', function($http, $cordovaOauthUtility, $cordovaOauth, $state) {
/*=================================================
Twitter Local Storage Functions and Keys
=================================================*/
var twitterKey = "STORAGE.TWITTER.KEY";
var twitterUserProfile = "STORAGE.TWITTER.USER";
/** Store Twitter User Profile in Local Storage**/
function storeTwitterProfile(data) {
window.localStorage.setItem(twitterUserProfile, JSON.stringify(data));
}
/** Get Twitter User Profile in Local Storage**/
function getStoredTwitterProfile() {
return window.localStorage.getItem(twitterUserProfile);
}
/** Store Twitter access_token in Local Storage**/
function storeTwitterToken(data) {
window.localStorage.setItem(twitterKey, JSON.stringify(data));
}
/** Get Twitter access_token in Local Storage**/
function getStoredTwitterToken() {
return window.localStorage.getItem(twitterKey);
}
/**
* Convert an image
* to a base64 url
* @param {String} url
* @param {Function} callback
* @param {String} [outputFormat=image/png]
*/
function convertImgToBase64URL(url, callback, outputFormat) {
var img = new Image();
img.crossOrigin = 'Anonymous';
img.onload = function() {
var canvas = document.createElement('CANVAS'),
ctx = canvas.getContext('2d'),
dataURL;
canvas.height = this.height;
canvas.width = this.width;
ctx.drawImage(this, 0, 0);
dataURL = canvas.toDataURL(outputFormat);
callback(dataURL);
canvas = null;
};
img.src = url;
}
/*=================================================
Twitter Login and Get Profile Section
...