Create Snapshot/Thumbnail of a blog entry using mvc - asp.net-mvc

I need to generate a snapshot from multiple links of blogs.
What i have is a list of text like these
"Report: Twitter Will Release Music Discovery App This Month http://on.mash.to/10L1v49 via #mashable"
I want to show the links as snapshot of the blog, followed by its text in my view. Or at least i need to get the picture attached to the blog.
Using facebook debug, http://developers.facebook.com/tools/debug ,i am getting this..
fb:app_id: 122071082108
og:url: http://mashable.com/2013/03/13/twitter-music-app/
og:type: article
og:title: Report: Twitter Will Release Music Discovery App This Month
og:image:
og:description: Twitter is planning to release a standalone music app for iOS called Twitter Music as soon as the end of this month, according to CNET. CNET reports that Twitter Music will help...
og:site_name: Mashable
og:updated_time: 1363267654
I tried the same link from my c# code, accessed the link with parameter 'q' as my desired link. I got the same html as reply but i am unable to find the image associated as it is coming differently for different links.
Can anyone suggest a better method to do this in mvc?
My code in controller to access facebook debug :
var client = new RestClient
{
BaseUrl = "http://developers.facebook.com/tools/debug/og/object"
};
var request = new RestRequest
{
DateFormat = DataFormat.Xml.ToString(),
Resource = "Add",
Method = Method.GET
};
request.AddParameter("q", "http://on.mash.to/10L1v49");
IRestResponse response = client.Execute(request);
var content = response.Content; // raw content as string

What i understand from your question is, you need something like the preview of a link what we get on pasting some link on facebook share area.
Facebook debug method returns an html page which has the image of your blog entry from the link given.
Use HtmlAgilityPack to parse your html returned from facebook debug
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(content);
HtmlNode root = doc.DocumentNode;
var imageurl = doc.DocumentNode.SelectNodes("//img/#src").LastOrDefault();
string imagesrc = imageurl.OuterHtml.ToString();
int start = imagesrc.IndexOf("url=");
int to = imagesrc.IndexOf("\"", start + "url=".Length);
string s = imagesrc.Substring(
start + "url=".Length,
to - start - "url=".Length);
string a = Uri.UnescapeDataString(s);
and..there you have your image of the blog entry. Same function can be modified to retireve the title, description and the updated time of the blog entry.

Related

How to get link to third party site in 'about channel' section via python

I want to display information about links in the YouTube profile in a text document, I tried to do it through the requests library, but Google gave links to privacy and security, I did not find information about this in the YouTube API documentation. Who knows, you can help with this
This isn't possible to get using the YouTube API, I actually found myself needing to do the same thing as yourself and was not able to because the YouTube API lacked the necessary functionality (Hopefully, It will be added soon!)
I see you mentioned Python, My only solution is in Node but I will do a large explanation and you can base your code off of it. In order to get the banner links without the YouTube API, we need to scrape the data, since YouTube uses client-side rendering we need to scrape the JSON configuration from the source.
There's a variable defined inside a script called ytInitialData which is a big JSON string with a massive amount of information about the channel, viewer, and YouTube configurations. We can find the banner links by parsing through this JSON link.
const request = require("request-promise").defaults({
simple: false,
resolveWithFullResponse: true
})
const getBannerLinks = async () => {
return request("https://www.youtube.com/user/pewdiepie").then(res => {
if (res.statusCode === 200) {
const parsed = res.body.split("var ytInitialData = ")[1].split(";</script>")[0]
const data = JSON.parse(parsed)
const links = data.header.c4TabbedHeaderRenderer.headerLinks.channelHeaderLinksRenderer
const allLinks = links.primaryLinks.concat(links.secondaryLinks || [])
const parsedLinks = allLinks.map(l => {
const url = new URLSearchParams(l.navigationEndpoint.commandMetadata.webCommandMetadata.url)
return {
link: url.get("q"),
name: l.title.simpleText,
icon: l.icon.thumbnails[0].url
}
})
return parsedLinks
} else {
// Error/ratelimit - Handle here
}
})
}
The way the links are scraped is as follows:
We make a HTTP request to the channel's URL
We parse the body to extract the JSON string that the banner links are inside using split
We parse the JSON string into a JSON object
We extract the links from their JSON section (It's a big JSON object data.header.c4TabbedHeaderRenderer.headerLinks.channelHeaderLinksRenderer
Because there are two types of links (Primary, the one that shows the text and secondary, links that don't show the text) we have to concatenate them together so we can map through them
We then map through the links and use URLSearchParams to extract the q query parameter since YouTube encrypts their outgoing links (Most likely for security reasons) and then extract the name and icon too using their appropriate objects.
This isn't a perfect solution, should YouTube update/change anything on their front end this could break your program easily. YouTube also has rate limits for their software if you're trying to mass scrape you'll run into 429/403 errors.

Google Youtube API v3 Playlist title

I am trying to port a application developed using version 2 API of google youtube to version 3.
How can I get title of a playlist using version 3 API? We could get the title of playlist using version 2. However, title I get when I query playlist's snippet is different from what it is shown on the youtube website.
Is there any difference in Version 3?
I am using .NET API library from Google. if this helps.
Can anyone please help?
EDITED: 20-MAY-2014
Sorry for the delay in response. I tried using Version 3 API from Google and when I am trying to get playlists using
var channelsListRequest = youtubeService.Channels.List("snippet,contentDetails");
after setting channelsListRequest.ForUserName, i call var channelsListResponse = await channelsListRequest.ExecuteAsync();
From the response, I would then get the playlist list sent using:
foreach (var channel in channelsListResponse.Items)
{
var uploadsListId = channel.ContentDetails.RelatedPlaylists.Uploads;
var nextPageToken = "";
while (nextPageToken != null)
{
var playlistRequest = youtubeService.Playlists.List("id,snippet,contentDetails,status,player");
playlistRequest.Id = uploadsListId;
playlistRequest.MaxResults = 50;
playlistRequest.PageToken = nextPageToken;
var playlistListResponse = await playlistRequest.ExecuteAsync();
if (playlistListResponse.Items.Count > 0)
MessageBox.Show(playlistListResponse.Items[0].Snippet.Title);
}
The messagebox displays the comment that was added when creating playlist. However, when I view in youtube using a browser, the playlist title is displayed properly.
Please try the following link, and change the play
https://www.googleapis.com/youtube/v3/playlists?part=snippet%2Clocalizations&id=" + playlistId + "&fields=items(localizations%2Csnippet%2Flocalized%2Ftitle)&key=" + KEY;
Implementation and Migration Guide: https://developers.google.com/youtube/v3/guides/implementation
I am new to the YouTube API implementation, so please use the Implementation and Migration Guide above for more information, but from what I have discovered myself using the API Explorer: https://developers.google.com/apis-explorer/#p/youtube/v3/. Is that you need to use youtube.playlists.list(snippet,[id]). Replace [id] with the ID of your playlist.

Twitter API 1.1 - render twitter's t.co links

I want to display the tweets of an account in my website. The problem is that the tweets appear always with the format http://t.co/..., instead of the full link as desired by me.
For instance, I obtain:
the rules of the game are all implemented - local players can play together in this link: http://t.co/Nf7j4TaB
if you are very curious... then, here is the link to the xodul's section under development: http://t.co/6Zbti36T
etc...
and I want that these tweets appear like this:
the rules of the game are all implemented - local players can play together in this link: http://xodul.com/tests/js/
if you are very curious... then, here is the link to the xodul's section under development: http://xodul.com/tests
etc...
To make my application I've followed the instructions from:
Simplest PHP example for retrieving user_timeline with Twitter API version 1.1 (from here we can get the text of each tweet, with the links coming in the format: http://t.co/...)
Rendering links in tweet when using Get Statuses API 1.1 (the code of the highest scored answer, in this link replaces, for instance, the text "http://t.co/Nf7j4TaB" with the hyperlink "<a target='_blank' href='http://t.co/Nf7j4TaB'>http://t.co/Nf7j4TaB</a>")
I appreciate very much any help on how to render the twitter's links!
With the tutorial you followed you can use these attributes to show actual link.
Note: In API v1.1, entities will always be included unless you set include_entities to False or 0.
The urls entity
An array of URLs extracted from the Tweet text. Each URL entity comes with the following attributes:
url: The URL that was extracted
display_url: (only for t.co links) Not a URL but a string to display instead of the URL
expanded_url: (only for t.co links) The fully resolved URL
indices: The character positions the URL was extracted from
https://dev.twitter.com/docs/tweet-entities
JavaScript only solution for now to get Twitter posts on your site without using new 1.1 API and actually returns the full url in posts, not the twitter shortened version :-) http://goo.gl/JinwJ
Thank you for your answers.
After analyzing the JSON in the suggested link (https://dev.twitter.com/docs/tweet-entities), I wrote a solution to the exposed problem:
// ...
$twitter_data = json_decode($json); // last line of the code in: http://stackoverflow.com/questions/12916539
// print the tweets, with the full URLs:
foreach ($twitter_data as $item) {
$text = $item->text;
foreach ($item->entities->urls as $url) {
$text = str_replace($url->url, $url->expanded_url, $text);
}
echo $text . '<br /><br />';
// optionally, here, the code from: http://stackoverflow.com/questions/15610968/
// can be added, too.
}

Feed link doesn't work

I'm using the Facebook PHP SDK to developp my app.
From this morning, when I publish an automatic post on a user's feed, everything is ok but the link doesn't work anymore... (no reaction on click)
Once the feed is published, the target of the link is "http://www.facebook.com/connect/uiserver.php?app_id=2711...site.com/annonce?a=62&response_type=code&display=page" (and doesn't work)
I replace the name of my website by mysite.com for this example
Here is my code :
$feed_message = utf8_encode("J'ai besoin de : ".$A_titre);
$feed_picture = "http://www.mysite.com/graph/icon.png";
$feed_link = "http://www.mysite.com/annonce?a=".$ins_id; // go to my website not app
$feed_linkname = utf8_encode($A_titre);
$feed_description = utf8_encode($me_firstname)." a besoin de...";
$result = $fb->api('/me/feed/','post',array('message'=>$feed_message,'picture'=>$feed_picture,'link'=>$feed_link,'name'=>$feed_linkname,'description'=>$feed_description));
Do you have any idea of what i can do to fix it ?
Thanks
I have the same problem. It seems that it's linked to the new "Enhanced Auth Dialog".
I deactivated it since the timeline is not ready anyway, and there's no more http://www.facebook.com/connect/uiserver.php?app_id= appended to the links on the user's wall.

Rss20FeedFormatter is producing RSS that is not well formed

I am using ASP.Net MVC2 and have a RSS feed for my blog. I am using out of the box functionality in System.ServiceModel.Syndication and Rss20FeedFormatter.
The feed works fine and can be read by Outlook as well as every browser I have tried. However when I submitted the RSS feed to google as a sitemap I got validation errors.
Out of curiosity I validated the feed with feedvalidator which reported similar issues.
Feed: http://www.chrispfarrell.com/Blog/Rss
If you pop this feed in at feedvalidator.org you will see the problems.
There is really no custom code going on to generate the RSS.
The controller action is
public FeedResult Rss()
{
const string baseUrl = "http://www.chrispfarrell.com/Blog/View/";
var blogs = _blogService.GetBlogs();
var feed = new SyndicationFeed
{
Title = new TextSyndicationContent("Chris Farrell"),
Copyright = new TextSyndicationContent("Copywrite Chris Farrell 2010")
};
var postItems = blogs.Take(25)
.Select(p => new SyndicationItem(p.Title,p.Body,new Uri(baseUrl + p.BlogUrl))
{
PublishDate = p.DateCreated,
});
feed.Items = postItems;
return new FeedResult(new Rss20FeedFormatter(feed));
}
Any comments as to why the feed would not be valid and well formed? I can post the code for FeedResult if needed but its pretty standard code.
Thanks
Chris Farrell
The Feed was missing the <link> element in the root <channel> element.
Rather than using an object initializer, I am using one of the constructors now which accepts 3 arguments(feed title, description and feed alternate link). The third argument for feed alternate link renders in the root channel <link> tag which makes the feed now valid.

Resources