Sharing Emoji to Twitter feed with Appcelerator - twitter

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?

Related

Using Google Script to send an email with a Word doc attachment

I have a google script that sends an email with a Word doc as an attachment. It used to work until google deprecated OAuth 1.0
This is the line that's failing:
var doc = UrlFetchApp.fetch(url+'download/documents/Export?exportFormat=doc&format=doc&id='+ copyId, googleOAuth_('docs',url)).getBlob();
If I remove the second parameter, i.e. function call to OAuth, it should work? Why do I need to authenticate? It should be able to fetch the document using an ID from google drive. It appears to work (because I don't see any errors), however, when I get an email there is a corrupt word doc attachment.
So, I tried implementing OAuth 2.0. But I'm not getting anywhere. Here's my code:
function getDriveService() {
return OAuth2.createService('drive')
.setAuthorizationBaseUrl('https://accounts.google.com/o/oauth2/auth')
.setTokenUrl('https://accounts.google.com/o/oauth2/token')
.setClientId(CLIENT_ID)
.setClientSecret(CLIENT_SECRET)
.setCallbackFunction('authCallback')
.setPropertyStore(PropertiesService.getUserProperties())
.setScope('https://www.googleapis.com/auth/drive')
.setParam('login_hint', Session.getActiveUser().getEmail())
.setParam('access_type', 'offline');
//.setParam('approval_prompt', 'force');
}
function authCallback(request) {
var driveService = getDriveService();
var isAuthorized = driveService.handleCallback(request);
if (isAuthorized) {
return HtmlService.createHtmlOutput('Success! You can close this tab.');
} else {
return HtmlService.createHtmlOutput('Denied. You can close this tab');
}
}
var oauth2Service = getDriveService();
var token = oauth2Service.getAccessToken();
var parameters = { method : 'get',
headers : {'Authorization': 'Bearer '+ token}};
var options =
{
"method" : "get"
};
var resp = UrlFetchApp.fetch('https://docs.google.com/feeds/download/documents/Export?exportFormat=doc&format=doc&id='+ copyId, parameters);
doc = resp.getBlob();
I'm getting a generic error [Access not granted or expired]. All I want is to be able to send an email with an attachment that is a document (format doc or docx) stored from my Google drive. Seems impossible! I'm able to attach this doc as a pdf but NOT a Microsoft document.
Any help will be greatly appreciated!
https://github.com/googlesamples/apps-script-oauth2 - look at setup
...
Have you added OAuth 2.0 in the libraries?
Resources -> Libraries -> then add 'MswhXl8fVhTFUH_Q3UOJbXvxhMjh3Sh48'

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.

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);
}
});
}

Make my web app authorize with google oAuth

I am trying to login with Google oAuth. But when ever i try to login with oAuth it ask for permission. From the code i realize that there need to add the authorization . I have gone through web and found another way to make the app authorize which is complete different than what i have used here. Is there any way so that i can just modify or add a function so that i will be able to make my app authorize with google oAuth ? I am using php and javascript for my web app.
var loginFinished = function(authResult)
{
if (authResult['status']['signed_in']) {
var btnLogOut=document.getElementById("social-integration-logout");
accessToken=authResult['access_token'];
expiresIn=authResult['expires_in'];
console.log(authResult);
gapi.client.load('oauth2', 'v2', function()
{
gapi.client.oauth2.userinfo.get()
.execute(function(resp)
{
var id = resp.id;
});
});
} else {
console.log('Sign-in state: ' + authResult['error']);
}
};
var options = {
'callback': loginFinished,
'approvalprompt': 'force',
'clientid': '',
'scope': 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile',
'requestvisibleactions': 'http://schemas.google.com/CommentActivity http://schemas.google.com/ReviewActivity',
'cookiepolicy': 'single_host_origin'
};
var renderBtn = function()
{
gapi.signin.render('btn_google_login', options);
}
Could you explain what issue you are having, i.e., what is not working? I notice that your script has 'approvalprompt': 'force', which will force the authorization dialog to always display. You may want to remove it so that returning users do not have to consent again. But I am not confident that this was your question.

(Facebook C# SDK) FacebookWebContext.Current.IsAuthenticated always return false

Hi guys im using the facebook c# sdk 5.0.50 to get the email and name of a facebook account in a web application but the FacebookWebContext.Current.IsAuthenticated always return false and the fbWebContext.UserId is always 0 (zero) even if im logged in facebook.
I already configured my web.config with my AppId and my AppSecret. I also copied the Facebook.dll and the Facebook.Web.dll to my Bin folder. Im using the Facebook Javascript SDK to do the logging part. Is there something im missing?
Here is my code
The logging Part:
FB.login(function (response) {
if (response.authResponse) {
FB.api('/me', function (response) {
console.log('Good to see you, ' + response.name + '.');
window.location.reload();
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, { scope: 'email,user_birthday' });
And in the code behind Im using the following code:
If fbWebContext.IsAuthenticated Then
Dim fb = New FacebookWebClient(fbWebContext)
Dim meInfo = CType(fb.Get("me"), Dictionary(Of String, Object))
Dim firstName As String = meInfo("first_name")
Dim lastName As String = meInfo("last_name")
Dim email As String = meInfo("email")
Mensaje.Text = String.Concat("code: ", firstName)
Else
Mensaje.Text = "not authorized - " & fbWebContext.Settings.AppId & " -" & fbWebContext.Settings.AppSecret
End If
I can display the info using the Facebook Javascript SDK but i need to do this in the server because after i get the user i need process it to see if he is in our database
Please some help
Thanks in advance
Looks like it was a bug with the framework (see http://facebooksdk.codeplex.com/workitem/5893) You should get the latest version, the fix is in it.

Resources