How can i get the URL of a tweet? - twitter

getUserTimeline(...) return a list of tweets. from this list there is a way to find out for each tweet, its url?
something like
List<Tweet> tweets = getUserTimeline("userId");
for(Tweet tweet:tweets){
tweet.urlOfTweet(); <--------???
}

I normally do it like that if you need just the URL of a specific tweet:
List<Tweet> tweets = getUserTimeline("userId");
for(Tweet tweet : tweets){
//Do something with the URL
tweet.getSource();
}
You can check here for further details what can be accessed from each tweet.

Related

Google Youtube API Search doesn't retrieve all videos in the channel

I have to retrieve all video of my channel with Youtube API.
All videos are published on Youtube and I can see them correctly.
I tried to make the request directly from this page:
https://developers.google.com/youtube/v3/docs/search/list
and this is the example request:
GET http s://www.googleapis.com/youtube/v3/search?part=snippet&channelId=myChannelID&maxResults=50&key={YOUR_API_KEY}
Request doesn't retrieve all videos, it returns only 7 on the total of 9.
All videos have the same configuration. Missing videos are always the same.
If I use the video API passing the ID of one of those videos excluded from the search response, it returns a correct response and it belong correctly to my channel:
https://developers.google.com/youtube/v3/docs/videos/list#try-it
Someone can help me?
thank you in advance
Francesco
The answer to "How do I obtain a list of all videos in a channel using the YouTube Data API v3?" here may be what you need. Look especially at the video linked to in the answer.
To summarize, to get all the uploads from a channel, you need to get the items from the uploads playlist for the channel using playlistItems.list on that playlist's ID rather than calling search.list on the channel ID.
Try this two-step approach:
Get the ID of your channel's uploads playlist using the channels.list API call: GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id={YOUR_CHANNEL_ID}&key={YOUR_API_KEY}
Get the videos from the uploads playlist using the playlistItems.list call: GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=3&playlistId={YOUR_PLAYLIST_ID}&key={YOUR_API_KEY}
try this
async static Task<IEnumerable<YouTubeVideo>> GetVideosList(Configurations configurations, string searchText = "", int maxResult = 20)
{
List<YouTubeVideo> videos = new List<YouTubeVideo>();
using (var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
ApiKey = configurations.ApiKey
}))
{
var searchListRequest = youtubeService.Search.List("snippet");
searchListRequest.Q = searchText;
searchListRequest.MaxResults = maxResult;
searchListRequest.ChannelId = configurations.ChannelId;
searchListRequest.Type = "video";
searchListRequest.Order = SearchResource.ListRequest.OrderEnum.Date;// Relevance;
var searchListResponse = await searchListRequest.ExecuteAsync();
foreach (var responseVideo in searchListResponse.Items)
{
videos.Add(new YouTubeVideo()
{
Id = responseVideo.Id.VideoId,
Description = responseVideo.Snippet.Description,
Title = responseVideo.Snippet.Title,
Picture = GetMainImg(responseVideo.Snippet.Thumbnails),
Thumbnail = GetThumbnailImg(responseVideo.Snippet.Thumbnails)
});
}
return videos;
}
}

twitter api tweet id to 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;

Displaying shorten goo.gl urls statistics on goo.gl panel

I'm shortening my "news" page's long URLs by using this code.
var api_key = 'AIzaSyCNGB0ddmvRkn5h************';
var docURL = document.URL;
function makeRequest() {
var request = gapi.client.urlshortener.url.insert({
'resource': {'longUrl': docURL}
});
request.execute(function(response) {
var newItem = {
url : response.id
}
$(".googlURL").html($("#shareButtons").tmpl({url : response.id , title : $('.newsDetail h3').text()));
});
}
function load() {
gapi.client.setApiKey(api_key);
gapi.client.load('urlshortener', 'v1', makeRequest);
}
this code creates goo.gl URL perfectly.
When someone visit the news details, it creates a shorten url automatically even any url is not created before.
But i would like to see the URLs in my goo.gl panel.
When i visit http://goo.gl/ with my account, i can not see how many URLs created and how many times they visited.
Is there a way to do this?
Thanks
I have found a solution as below about your question. May be that can help you
If you have already created a shortened goo.gl url just type .info at
the end (e.g. goo.gl/url.info)

Get Twitter card from API

I would be able to retrieve HTML markup of what is stored in Twitter Card (https://dev.twitter.com/docs/cards).
Up until now I used TweetSharp library to retrieve tweets from some user's timeline. But, what is not surprising, because cards are new thing, it is not included.
Does anyone know, if it is possible to access card (data cached by Twitter crawler) with API?
The Twitter cards themselves are not exposed through the Twitter API.
What you'll need to do is make a request to the URL mentioned and examine the <head> element to see if they have the Twitter Card info in there.
Twitter apis do not provide the twitter-card info out of the box. You can extract the card info for a url by looking it up in its html. Below code in csharp gets card image src from the url-
public static TweetMedia[] GetTwitterCardDetails(string url)
{
string HTML;
using (var wc = new WebClient())
{
HTML = wc.DownloadString(url);
}
var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(HTML);
HtmlNode element = doc.DocumentNode.SelectSingleNode("//meta[#name='twitter:image:src']");
if (element != null)
{
return new TweetMedia[] { new TweetMedia { url=url, media_url_https = element.Attributes["content"].Value, type = TweetTypes.TweetType.Photo.ToString() } };
}
return null;
}

DotNetOpenAuth detect fetch request like google

With google, you can fetch the user's email like this:
var fetch = new FetchRequest();
fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
request.AddExtension(fetch);
and get it back like this:
var fetch = response.GetExtension<FetchResponse>();
string email = "";
if (fetch != null)
{
email = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email);
}
When writing a provider, how can I return the values asked for?
The OpenIdProviderWebForms sample that comes with DotNetOpenAuth includes returning user attributes. Have you checked it out?

Resources