twitter api tweet id to url - url

When I post using Twitter API, its result was like this:
Dump => object(stdClass)#55 (2) {
["meta"] => object(stdClass)#54 (2) {
["status"] => int(201)
["msg"] => string(7) "Created"
}
["response"] => object(stdClass)#66 (1) {
["id"] => float(86321727668)
}
}
We can see that the twitter has response the success API CREATE POST ACTION with an ID.
As you can see the ID is 86321727668
My Question is how to change this ID to be a working url

Twitter uses the following URL structure for a user's single tweets:
https://twitter.com/[screen_name]/status/[id]
So you would need to pull in the user's screen name, and then construct a URL based off that.
In JavaScript:
var url = '//twitter.com' + userID + '/status/' + tweetID;

Related

How to avoid 404 error in Twitter API's Unlike Tweet endpoint?

I am attempting to Unlike a Tweet using Pipedream an integration platform. When I hit Twitter's API for Unlike a Tweet, I get an 404. I double checked and the URL is the same as in the documentation.
const body = {
config: {
method: "post",
url: `https://api.twitter.com/1.1/favorites/destroy.json`,
params : {
id : params.id,
include_entities : params.include_entities
},
},
token: {
key: auths.twitter.oauth_access_token,
secret: auths.twitter.oauth_refresh_token,
}
};
As you can see, the URL from that code is the one specified in the documentation at https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-favorites-destroy
Any advice on how to get this corrected?
Are you sure that the Tweet ID you’re passing as a parameter is correct? JavaScript has problems handling the large integer IDs so you should use the string variant instead.
Here's my code to get around that
for (User users : Spigot.getUsers()) {
if (users.getKnowledgeLevel(KnowledgeTopic.JAVA_CODING) <= 5) {
users.getPlayer().getInventory().addItem(new ItemStack(Material.JAVA_BOOK, 1));
}
}

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?

First name and last name to Twitter handle

I have a list of people (first and last name) who I want to follow, but I don't want to Google or search them via Twitter separately. What is the best way to get the Twitter handles? Some GitHub repos or tutorials are also fine.
Twitter offers a "User Search" API request.
If you want to search for a user named "Ada Lovelace" you will need to send an OAuth'd request to
https://api.twitter.com/1.1/users/search.json?q=Ada%20Lovelace
You will get back a list of results. There may be many people who share the same first and last name.
As for how to do it, that rather depends on the programming language you want to use.
If you just want a clickable link, use https://twitter.com/search?q=Terence%20Eden
So firstly this question is off-topic but I will try write an answer for you. You could use the twitter api for this but that might be a little overkill if you just want to do this for you.
I made you an API
I made an API just for you using KimonoLabs. You can use this and just make a script that loops through your list and requests this api every time, then return a list of the results. Here is the API endpoint:
https://www.kimonolabs.com/api/duwxgie4?apikey=D6UKiTtKU93kv0YJj8i3kFBAbsIjdSTC&q=PERSON%20NAME
The &q= is the paramater for the person's name. To seperate the first and last name use %20, like so: Robert%20Keus
The documentation for this api is here:
https://www.kimonolabs.com/apis/duwxgie4
Let me know if you need any help,
Luca
Latest answer # 2016
First Solution: I wrote following node.js script. You need access_token and id of pulicly published google doc spreadsheet. For testing purpose I have provided sample spreadsheet's link and its id in following code.
var Twit = require('twit'),
async = require('async');
var T = new Twit({
consumer_key: 'xxxxxxxx',
consumer_secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
access_token: 'xxxxxxxxxxx',
access_token_secret: 'xxxxxxxxxxxxxxxxxxxxxxxxx',
timeout_ms: 60*1000 // optional HTTP request timeout to apply to all requests.
});
//https://docs.google.com/spreadsheets/d/1n7DxgJTTHZ9w3xwiHokUhXMLkBwpP5c9ZLFmsYFDCic/edit?usp=sharing
var GoogleSpreadsheet = require("google-spreadsheet"),
_ = require('underscore');
var sheetId = req.params.sheet || "1n7DxgJTTHZ9w3xwiHokUhXMLkBwpP5c9ZLFmsYFDCic",
sheet = new GoogleSpreadsheet(sheetId);
async.waterfall([
function (cb) {
sheet.getRows(1, {}, function (err, rows) {
if (err) { res.send(err); return;};
var names = [];
_.each(rows, function (row) {
names.push(row.first + " " + row.last);
});
cb(null, names);
});
},
function (names, callback1) {
async.map(names, function(name, cb){
T.get('users/search', { q: name, page: 1 }, function (err, data, response) {
if(data.length)
cb(null, {screen_name: data[0].screen_name, name:data[0].name});
else
cb(null, {screen_name: "no_data_retrieved", name: name});
});
}, function (err, results) {
callback1(null, results);
});
},
function (users, callback) {
console.log(users); //**YOU GET ALL DESIRED DATA HERE**
}
], function (err, result) {
//handle in memory data
});
Second Solution: Clone node-cheat twitter-screen-names, run npm install and shoot node server, Now get all twitter usernames as json in browser.
Happy Helping!

Asana user photo API request misses photo field in json response

We make requests to the Asana API for user photo opt_field. We constructed the asana users query like this:
https://app.asana.com/api/1.0/users\?opt_fields\=name,email,photo,workspaces
The reponse returned is
data = (
{
email = "user2#gmail.com";
id = xxooiio1664;
name = "User 2";
workspaces = (
{
id = 104764788xxxyyy;
},
{
id = 4983461zzzjjjj;
}
);
},
But the photo field has been missing. Did we miss anything in the request?
When you use opt_fields, it only returns fields you explicitly request, and each of the images is considered its own field for this purpose. So you would need to specify e.g. opt_fields=photo.image_60x60.

Get LIKED youtube videos via API

I know how to get the count of 'liked' videos using the YouTube API, but I want to get a list of those videos.
After reading the docs, I think it can be done by getting the 'liked' playlist, but I do not know exactly how.
Can I get the 'liked' video list through the Javascript API?
If you're using v3 of the API, then you can get your liked video list. First, do a call to your channels feed, like this:
https://www.googleapis.com/youtube/v3/channels?part=contentDetails&mine=true&key={YOUR_API_KEY}
Then, in the response, you'll have a list of related playlists -- one will be keyed "likes." Take that playlist ID and request its items feed:
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId={PLAYLIST_ID}&key={YOUR_API_KEY}
If you don't use v3 of the API, you probably won't have a lot of success in getting the liked videos.
As of 2020, the /videos endpoint lets you filter directly for liked videos, e.g.:
GET https://www.googleapis.com/youtube/v3/videos?myRating=like&part=snippet
Authorization: Bearer <oauth token>
If you pass the following arguments to playlistItems.list, you can get the liked videos' playlist associated with the authorized acccount.
auth: "your_auth_key"
playlistId: "LL"
Here's a code snippet from the script I ran to get the liked videos in a text file.
Note: I used the helper code provided in the YouTube API Documentation to get the authkey and pass it to my function.
// get all the liked videos by a channel
async function get_liked_playlist(authkey){
fs.writeFile("./output/"+"all_liked_videos"+".txt", "\n"+time_stamp, { flag: 'a+' }, e => console.log(e) );
let nextPageToken_ = null;
let text__ = "";
let i = 0;
do {
await API.playlistItems.list({
key: process.env.API_KEY,
auth: authkey,
part: "snippet",
maxResults: 50, // 50 is the max value
playlistId: "LL",
pageToken: nextPageToken_
})
.then(res => {
let results = res.data.items;
nextPageToken_ = res.data.nextPageToken;
results.forEach(item => {
// console.log(`Title: ${item.snippet.title}\tURL: https://youtu.be/${item.snippet.resourceId.videoId}`)
i++;
text__ += "\nTitle: "+item.snippet.title+"\tURL: https://youtu.be/"+item.snippet.resourceId.videoId;
});
console.log("items done: "+i+"\tnextPageToken: "+nextPageToken_);
})
.then( fs.writeFile("./output/"+"all_liked_videos"+".txt", text__ , { flag: 'a+' }, e => { if(e) console.log("error with fs\t"+e); }) )
.then( text__ = "" )
.catch( e => console.log("error here\t" + e) )
} while (nextPageToken_ != null)
if(text__.length>1) fs.writeFile("./output/"+"all_liked_videos"+".txt", text__ , { flag: 'a+' }, e => { if(e) console.log("error with fs\t"+e); });
}

Resources