The new Twitter v2 API was just released a couple of weeks ago, so this may just be an issue of the documentation not being done quite yet.
What I am trying to do is search recent tweets for "puppies" and return all that have some kind of media attached. However, when I run this search in Postman, not all of the returned tweets have attachments.media_keys. I noticed that the ones that do not have attachments.media_keys are tweets whose text ends in ellipses .... I understand that in the v1.1 API, this issue is solved by specifying tweet_mode=extended in the query params or tweet.fields=extended_tweet. However, these do not seem to work in the v2 API and I have not seen any documentation about getting the full text of tweets (and the associated attachments). Does anyone know how to do this in v2?
My Postman query url: "https://api.twitter.com/2/tweets/search/recent?query=has:media puppies&tweet.fields=attachments&expansions=attachments.media_keys&media.fields=duration_ms,height,media_key,preview_image_url,public_metrics,type,url,width"
In my app, I am using Node.js Axios to perform the query:
var axios = require('axios');
var config = {
method: 'get',
url: 'https://api.twitter.com/2/tweets/search/recent?query=has:media puppies&tweet.fields=attachments&expansions=attachments.media_keys&media.fields=duration_ms,height,media_key,preview_image_url,public_metrics,type,url,width',
headers: {
'Authorization': 'Bearer {{my berarer token}}',
}
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
As of July, 2021, for sure this "problem" or strange behavior concerns retweets.
To get full text of a retweet while getting recent tweets for a user I did the following trick:
First I get recent tweets for a user following docs:
curl "https://api.twitter.com/2/users/2244994945/tweets?expansions=attachments.poll_ids,attachments.media_keys,author_id,entities.mentions.username,geo.place_id,in_reply_to_user_id,referenced_tweets.id,referenced_tweets.id.author_id&tweet.fields=attachments,author_id,context_annotations,conversation_id,created_at,entities,geo,id,in_reply_to_user_id,lang,possibly_sensitive,public_metrics,referenced_tweets,reply_settings,source,text,withheld&user.fields=created_at,description,entities,id,location,name,pinned_tweet_id,profile_image_url,protected,public_metrics,url,username,verified,withheld&place.fields=contained_within,country,country_code,full_name,geo,id,name,place_type&poll.fields=duration_minutes,end_datetime,id,options,voting_status&media.fields=duration_ms,height,media_key,preview_image_url,type,url,width,public_metrics,non_public_metrics,organic_metrics,promoted_metrics&max_results=5" -H "Authorization: Bearer $BEARER_TOKEN"
This is an all fields query (not all fields are necessary) but it is necessary to get ['includes']['tweets'] within the structure of the returned JSON data. This is the place where you have to look for the full text of a retweet - it is at: ['includes']['tweets'][0..n]['text] while all the recent tweets (and retweets) are found at ['data'][0..n]['text'].
Then you have to match the shortened retweets from the ['data'] with those from the ['includes']['tweets']. I do it using ['data'][n]['referenced_tweets'][0]['id'] which should match ['includes']['tweets'][m]['id]. where n and m are some indexes.
To be 100% safe you can check if ['data'][n]['referenced_tweets'][0]['id'] has a matching key/value pair: type: retweet (suggesting that this is really a retweet reference), but for me the 0 index works in all checked cases so not to complicate things more I left it this way for now :)
If that sounds complicated just dump the whole parsed JSON with all tweets and check the structure of the data.
Great question, thank you. We’re discussing this on the Twitter Developer forums as well.
In v2 of the API we have eliminated the notion of an “extended Tweet” since we assume that all new apps understand the concept of 280 characters, so the complete text is in the Tweet text field.
The difference you’re finding is in retweets or quoted Tweets where the embedded text is truncated. This is (perhaps surprisingly) the same as v1.1 and the former premium and enterprise APIs as well. We are investigating whether to modify this, and the implications in doing so.
I don’t for any means want to take traffic away from Stack, but you might find more ongoing updates and information on our developer forums. Thanks!
I’m having an issue where buttons and actions in hero and adaptive cards won’t wrap text. I have searched the internet and everyone is mentioning a webchat.js and botchat.js files that can be adjusted to fix this. I can’t seem to find those in my code. Has the name changed? I know botchat was changed to webchat. Would anyone happen to know where to fix this in the Basic Bot NodeJS implementation SDK V4?
Assuming you are using webchat, you could use plain css. This worked for me:
.ac-pushButton > div {
white-space: normal !important;
}
I was able to find an answer in node_modules > wordwrap. There is a function that you can call in there to wrap any text you'd like. Thank you #Hessel for the help.
var wrap = require('wordwrap')(70);
return CardFactory.heroCard(
'',
answer,
CardFactory.images([]),
CardFactory.actions([
{
type: 'postBack',
title: wrap(YOUR_TEXT),
value: YOUR_VALUE
}
])
);
I would like to retrieve photos from an account with the Instagram Display API but I can't find anything on the documentation.
The closest thing to that is this https://developers.facebook.com/docs/instagram-basic-display-api/guides/getting-profiles-and-media?locale=en_US but it only allows you to recover photos of the person connected to the API. However, I would like to be able to recover photos of anyone from their username, or from a hashtag.
GET /me?fields={media}&access_token={access-token}
I also found this https://developers.facebook.com/docs/instagram-basic-display-api/reference/user/media but it is nowhere explained how to get someone's user-id from a username.
GET https://graph.instagram.com/{user-id}/media?access_token={access-token}
I find a way to do it without Instagram API (Sources https://stackoverflow.com/a/33783840/12739212) but I'm afraid they will change their code and therefore this solution will no longer work so I would like to do it with the Instagram API
$html = file_get_contents('https://instagram.com/' . $username . '/');
preg_match('/_sharedData = ({.*);<\/script>/', $html, $matches);
$profil_data = json_decode($matches[1])->entry_data->ProfilePage[0]->graphql->user;
$data_edges = $profil_data->edge_owner_to_timeline_media->edges;
foreach ($data_edges as $key => $value) {
$img_url = $value->node->display_url;
echo "<img src=" . $img_url . ">";
}
Thanks in advance.
Hello I found this tutorial in this link but its a lot of hassle, I would rather keep changing code rather going this stuff todo
So I finally gave up using the API and used this library instead https://github.com/postaddictme/instagram-php-scraper
I'm currently attempting to accept voice input from the user, feed it into the Bing Speech API to get text, and pass that text as a user response. I've gotten as far as receiving the text back from Bing, but I'm not sure how to send that text as a user response. I've been scouring GitHub, so any feedback is appreciated. Relevant code is below:
function(session){
var bing = new client.BingSpeechClient('mykey');
var results = '';
var wave = fs.readFileSync('./new.wav');
const text = bing.recognize(wave).then(result => {
console.log('Speech To Text completed');
console.log(result.header.lexical)
console.log('\n');
results.response = result.header.lexical;
});
}]
You should use session.send.
I recommend you to take a look to the intelligence-SpeechToText sample, where a similar scenario is being shown.
Update: Figured it out (sorta). In order to take advantage of sending this user input back, I had to use another card. Within the context of the card, I'm able to use the imBack function
This question came up on the etherpad-open-source-discuss mailing list and I thought it would be useful to have it here.
Just construct a URL like so and fetch it:
http://dtherpad.com/ep/pad/export/foo/latest?format=txt
That will get the live, plaintext contents of http://dtherpad.com/foo
For example, in PHP you can grab it with
file_get_contents("http://dtherpad.com/ep/pad/export/foo/latest?format=txt")
Note that that's just the "export to plain text" link that's provided in the Import/Export menu of every pad.
A few other possibilities:
From a browser, you can hit http://your-etherpad-server.com/ep/pad/view/padId/latest?pt=1
From within the code of the collaborative editor (ace2_inner.js), use rep.alltext
Within the Etherpad's javascript, use pad.text for the most recent version of pad.getRevisionText(rev.revNum) for a specified previous revision.
It seems that the javascript functions mentioned by Ari in his response are no longer present in the current versions of Etherpad as implemented on sites like http://etherpad.mozilla.org
However you can now simply use the following javascript function, within eherpad's javascript to get the text of the latest revision
padeditor.ace.exportText()
You can get the plaintext content of etherpad using jQuery as:
jQuery(document).ready(function(){
jQuery('#export').click(function(){
var padId = 'examplePadIntense';//Id of the div in which etherpad lite is integrated
var epframeId = 'epframe'+ padId;
var frameUrl = $('#'+ epframeId).attr('src').split('?')[0];
var contentsUrl = frameUrl + "/export/txt";
jQuery.get(contentsUrl, function(data) {
var textContent = data;
});
});
});
You can also use the getText HTTP api to retrieve the contents of a pad.
See my other answer for more details.