Titanium Twitter Access token error - twitter

I developing application in Titanium Appcelerator. I had share image to twitter using the social.js link..It was worked great till yesterday. and i dont know is there anything updated in api , my share is not working and my error states "Can't get Access token" .
MyCode:
var social = require('/ui/common/social_plus');
var twitter = social.create({
consumerSecret : '1bXxxxxxxxxxxxxxxxxT0raQbg2Bhx',
consumerKey : '3xxxxxxxxxxxxxxxffFx'
});
twitter.authorize(function() {
twitter.shareImage({
message : 'Share Via ',
image : pic_loc,
success : function() {
alert('tweeted Succesfully!');
},
error : function() {
alert("ERROR Tweeted!");
}
});
});

Related

Sharing Emoji to Twitter feed with Appcelerator

I have been using this method (https://github.com/ebryn/twitter-titanium) of authenticating with Twitter for a while now. I am currently using Ti Studio 4.2.0.201508141038, Ti SDK 3.5.1. I know this is a little old but I am on this version for support reasons.
I am trying to allow the sharing of text entered in a TextArea to twitter including emojis. For some reason sharing to Facebook works like a charm but twitter I receive "����". Please note that I have only tested iOS to date. Android will follow.
Is there some encoding method that I should be using that will get me through this?
The code I am using to post is simply as follows:
var Twitter = require('twitter').Twitter;
var client = Twitter({
consumerKey: consumerKey,
consumerSecret: consumerSecret,
accessTokenKey: accessTokenKey,
accessTokenSecret: accessTokenSecret
});
client.addEventListener('login', function(e) {
if (e.success) {
Ti.App.Properties.setString('twitterAccessTokenKey', e.accessTokenKey);
Ti.App.Properties.setString('twitterAccessTokenSecret', e.accessTokenSecret);
var tweet = textArea.value.replace(/[\n\r]/g, '');
client.request("1.1/statuses/update.json", {status: tweet, trim_user:'t'}, 'POST', function(e) {
if (e.success) {
console.log('success');
} else {
console.log('Twitter Post failed.\nDetail is:'+JSON.stringify(e.data));
}
});
} else {
Ti.API.debug(JSON.stringify(e));
}
});
client.authorize();
Funnily, I found that if I make tweet equal to:
var tweet = textArea.value.replace(/[\n\r]/g, '') + '\ue415';
I do get a smiley in my tweet but only on my device not on twitter.com. But if I type that code directly into my TextArea it gets tweeted verbatum.
I have also tried using encode(tweet) and urlEncode(tweet) but they really don't work.
Is there a way I can get emojis tranlated into text that will then post correctly on twitter?

Titanium Appcelerator API call error - HTTP ERROR

I am having a website which contains login page. When user tries to log in using username and password. Data is being passed in Form Data. Please have a look as following image to get idea.
Now I want to use the same api in my Titanium application and get all details or logged in user which i am performing using below mentioned code.
var url= "http://www.randomwebsite.com/login/";
var jsonData = {
username: "admin",
password: "password1"
};
var xhr = Ti.Network.createHTTPClient();
xhr.onload = function(e) {
var obj = JSON.parse(this.responseText);
alert("DATA IS " + JSON.stringify(obj));
};
xhr.onerror = function(e) {
Ti.API.info("ERROR " + e.error);
};
xhr.onsendstream = function(e){
Ti.API.info("onsendstream");
};
xhr.ondatastream = function(e){
Ti.API.info("ondatastream");
};
xhr.open('POST',url);
xhr.send(JSON.stringify(jsonData));
I am getting HTTP error. I even tried setting xhr.setHeader('Content-Type','application/json') as well as verified url its same as that is being used by website. Can any one help me out with this ? Or is there any way in order to make sure that titanium code passes data in form-data ? Or any suggestion regarding this would be of great help.
Its working fine now. Mistake that I was doing is that i was stringifying text when data was being send. So changing xhr.send(JSON.stringify(jsonData)) to xhr.send(jsonData) works for me. Hope so this would help some one.

The operation couldn’t be completed. (com.facebook.sdk error 5.)

I have a problem when created a new app in facebook and use it for sharing in Titanium with the Facebook Module , i get this error :
Error: HTTP status code: 403
[ERROR] : FB: The operation couldn’t be completed. (com.facebook.sdk error 5.)
So if i used my old (other) appid with the same code and and the same config in facebook apps section it works fine.
var fb = require('facebook');
fb.appid = "XXXXXXXXXXXXXXX";
fb.permissions = ['publish_stream', 'read_stream'];
if(!fb.loggedIn) {
fb.authorize();
}
var data = {
message: messageToShare,
picture: blobImageToShare
};
fb.requestWithGraphPath('me/photos', data, "POST", function(e){
if (e.success) {
Ti.API.info("FB: Success! Shared to FB: " + e.result);
}
else {
if (e.error) {
Ti.API.error('FB: '+ e.error);
}
else {
Ti.API.error("FB: Unkown result sharing");
}
}
});
Titanium version : 3.3.0
Titanium SDK 3.3.0
Platform & version : iOS >=6
Device: iOS simulator, iPhone 4 & 5.
any solution for this problem ?
You need to make sure the Facebook authorization completes before attempting to do a Graph query.
fb.authorize();
fb.addEventListener('login', function(e) {
Ti.API.debug('Returned from Facebook.');
if (e.success) {
Ti.API.debug('Authorized with Facebook, yeeey!');
// Query Graph now that we're authorized...
}
else if (e.error) {
Ti.API.debug('Error logging in with Facebook: ' + e.error);
}
else if (e.cancelled) {
Ti.API.debug('Cancelled logging in with Facebook.');
}
else {
Ti.API.debug('Something else. May actually be logged out.');
}
});
Also, make sure you define your Facebook appid in your tiapp.xml file:
<property name="ti.facebook.appid">xxxxxxxxxxxx</property>

Meteor acounts add info from Twitter accounts

I'm trying to figure out how I can add additional information from a user's Twitter account to the created account on a Meteor installation.
In particular I am trying to access the user's bio via Twitter Api v 1.1 and am not successful in doing so.
Therefore I am trying to extend Accounts.onCreateUser(function(options,user) {}); with the Twitter bio. How do I do that? And then access this data from a template?
Here's a perfect answer for returning data from Github, however I've had trouble porting this approach over to Twitter as the authenticating service: Meteor login with external service: how to get profile information?
You could do it on this way:
Accounts.onCreateUser(function (options, user){
user.profile = options.profile || {};
//Twitter returns some useful info as the username and the picture
if(user.services.twitter){
user.profile.picture= user.services.twitter.profile_image_url_https;
user.profile.username= user.services.twitter.screenName;
}
return user;
});
For getting the data from the Twitter API I´m using the node package oauth:
OAuth = Npm.require('oauth');
oauth = new OAuth.OAuth(
'https://api.twitter.com/oauth/request_token',
'https://api.twitter.com/oauth/access_token',
'consumerKey',
'secretKey',
'1.0A',
null,
'HMAC-SHA1'
);
getTwitterUserData: function (id) {
var accountUser = AccountsUserCollection.findOne({_id: id});
var url = "https://api.twitter.com/1.1/users/show.json?screen_name="+accountUser.screen_name;
oauth.get(url, 'accessToken', 'accessSecret', function (err, data, response) {
if(err){
console.log(err);
}
if(data){
Fiber(function () {
AccountsUserCollection.update({_id: accountUser._id}, {$set: {dataTwitter: JSON.parse(data)}});
}).run();
}
if(response){
Log.info(response);
}
});
}

"Incorrect Signature" by Twitter while update/status using OAuth.js library

i get an "Incorrect signature" error by Twitter Api while im posting an update to my twitter account from my app.
I use the javascript OAuth library oauth.js.
Here is my code:
consumer.Name =
{ consumerKey : "xxxxxxxdwcececwscwdc",
consumerSecret: "xxrtbujztvfdtcehz5tjv6uvjxbzuku7ik",
serviceProvider:{
signatureMethod : "HMAC-SHA1"
, requestTokenURL : "https://api.twitter.com/oauth/request_token"
, userAuthorizationURL: "https://api.twitter.com/oauth/authorize"
, accessTokenURL : "https://api.twitter.com/oauth/access_token"
, echoURL : "myApp.html"
}
}
function postTweet(consumerName, twitterText){
var accessor = consumer[consumerName];
message = {method: "POST",action: "http://api.twitter.com/1/statuses/update.json",
parameters:{
oauth_token: my_oauth_token// <-- here is the current oauth_token
status: twitterText,
}
}; // end of message
OAuth.completeRequest(message,
{
consumerKey : accessor.consumerKey,
consumerSecret : accessor.consumerSecret
}
);
var authorizationHeader = OAuth.getAuthorizationHeader("", message.parameters);
var requestBody = OAuth.formEncode(message.parameters);
var postTweetText = newXMLHttpRequest();
postTweetText.onreadystatechange = function receiveAccessToken(){
if (postTweetText.readyState == 4) {
blabla
}
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
postTweetText.open(message.method, message.action, true);
postTweetText.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
postTweetText.setRequestHeader("Authorization", authorizationHeader);//;
postTweetText.send(requestBody);//requestBody
}
}
What am i doing wrong?
}
coming in rather late on this question but hopefully this leads someone with similar issues to a solution.
I had the same response, but it was because I had set up OAuth with a different app, had saved those credentials and then tried posting to a different registered app on Twitter. Hence, an incorrect signature because I was trying to authenticate with a different app's credentials.
Fixed by nuking the binary and doing a clean/build.

Resources