Youtube V3 Data API - c#

I would like to know a very simple way of getting the list of videos that were uploaded by user/or videos in a channel.
For example, I want to retrieve basic information about videos those were posted in the Youtube spotlight channel (http://www.youtube.com/user/YouTube/videos). All I need is read-only publicly available information.
I am so lost with the Youtube v2/v3 API / Google APIs etc. I could partially make one example work but I think all the examples are heavily biased towards "third-party" access. I started developing one example by looking at their samples and when I compiled and ran the application - it was asking me to sign-in to my google account.
Any help is greatly appreciated. Thanks.

For the sake of simplicity you can use the api v2 like this:
const string channelName = "YourChannel";
var URL =string.Format("http://gdata.youtube.com/feeds/api/users/{0}/uploads",
channelName);
using (var reader = new XmlTextReader(URL))
{
while (reader.Read())
{
if (reader.Name.Equals("media:player"))
{
string attribute = reader["url"];
if (attribute != null)
{
Response.Write("Youtube Video Link" + attribute + "<br />");
}
}
}
}
You can achieve similarly using v3 but It will require some more work

Related

How to get the friends activities using twitter api?

I am not able to get list or collection from twitter api which returns my friends activities.
Basically I want the list of activities of my friends just like the twitter has activity or interaction section on its website.
You can do that with a Site stream. First, get a list of your friends ID's, then add them to the site stream. Here's an example using LINQ to Twitter:
Console.WriteLine("\nStreamed Content: \n");
int count = 0;
(from strm in twitterCtx.UserStream
where strm.Type == UserStreamType.Site &&
strm.Follow == "15411837,16761255"
select strm)
.StreamingCallback(strm =>
{
Console.WriteLine(strm.Content + "\n");
if (count++ >= 10)
{
strm.CloseStream();
}
})
.SingleOrDefault();
You can find more info in the LINQ to Twitter Documentation.
Also, regardless of what technology you go with, you should read Twitter's Site Streams documentation.
NOTE: Twitter site streams is in Beta, so you'll need to contact them for access.
To be able to monitor your friends on Twitter you need to use the UserStream (https://dev.twitter.com/docs/streaming-apis/streams/user).
Whilst its implementation is missing some features of the UserStream the Tweetinvi API gives the ability to easily detect what your friends do on twitter.
Here is an example :
// Register the Twitter Credentials
IToken token = new Token("userKey", "userSecret", "consumerKey", "consumerSecret");
// Create the stream
IUserStream userStream = new UserStream();
// Register to an event that triggers when a tweet is created by a user you follow
userStream .TweetCreatedByAnyoneButMe += (sender, args) =>
{
Console.WriteLine("Tweet '{0}' created by {1}!", args.Value.Text, args.Value.Creator.Id);
};
// Start the stream
userStream.StartStream(token);
This code is going to call the Console.Writeline() each time a Tweet is created by a user you follow!
As I said all the features are not implemented yet but you can already listen to many different events like Tweets, Messages, Follows... as well as filtering the Tweets you receive (which is not possible by default with Twitter UserStream).
Hope this will help you :)
EDIT : You can find the API there -> http://tweetinvi.codeplex.com/

post items from to amazon.com using API

What API I should use to post items from asp.net (C#) web application to amazon.com ?
please guide me to proper documentation and steps.
What I am looking for is how to add new item into certain category and pass the item title/description/pictures/price etc... -- plz advice
Thanks
You're question is a bit vague, but this was the most useful link I found when researching into how to interface with Amazon using C# -
http://flyingpies.wordpress.com/2009/08/01/17/
You need the Marketplace Web Services API. Found at http://developer.amazonservices.com.
You then need the flat file feed specifications to send the flat file in the correct format to the MWS. That can be found after you're logged into your seller central account:
https://sellercentral.amazon.com/gp/help/help.html/ref=ag_13461_cont_help?ie=UTF8&itemID=13461&language=en_US
From there, you can simply send to the MWS the data you need. Here is a snippet of my code:
SubmitFeedRequest req = new SubmitFeedRequest();
req.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(feedContent);
feedContent.Position = 0;
req.FeedContent = feedContent;
req.FeedType = "_POST_FLAT_FILE_INVLOADER_DATA_";
req.PurgeAndReplace = false;
req.Marketplace = MarketPlaceId;
req.Merchant = MerchantId;
return Service.SubmitFeed(req);
Assuming that by 'posting' you mean posting new items into the amazon marketplace, you can use
this api https://affiliate-program.amazon.com/gp/advertising/api/detail/main.html
Also google works wonders for searching
It sounds to me like you need the Amazon Market Place Feeds API.
https://developer.amazonservices.co.uk/gp/mws/api.html?ie=UTF8&section=feeds&group=bde&version=latest
You can use SubmitFeed to send product and inventory information to Amazon

How can I use Google Search in my C# project?

i build mini Question Answering System in C#. I need retrieve document by google Search.
What is google tools name, i can use it in my project?
Thanks
One possibility is to set up a custom Google search engine. Then you also need to create a developer key, which I believe is done under the console.
After setting that up, you can make REST style call with code such as the following, which retrieves the results as JSON:
WebClient w = new WebClient();
string result;
string uri;
string googleAPIKey = "your developer key";
string googleEngineID = "your search engine id";
string template = "https://www.googleapis.com/customsearch/v1?key={0}&cx={1}&q={2}&start={3}&alt=json";
int startIndex = 1;
int gathered = 0;
uri = String.Format(template, googleAPIKey, googleEngineID, "yoursearchstring", startIndex);
result = w.DownloadString(uri);
For extracting the information from the JSON results, you can use something like Json.NET. It makes it extremely easy to read the information:
JObject o = JObject.Parse(result);
Then you can directly access the desired information with a single line of code.
One important piece of information is that the search API free usage is extremely limited (100 requests per day). So for a real-world application it would probably be necessary to pay for the search. But depending on how you use it, maybe 100 requests per day is sufficient. I wrote a little mashup using the Google search API to search for Stackoverflow site information of interest and then used the StackExchange API to retrieve the information. For that personal use, it works very well.
I've never used it before (and it's alpha), but take a look at Google APIs for .NET Framework library.

Copy a Google Docs Spreadsheet using Google .NET API

I'm wanting to copy an already existing Google Docs Spreadsheet to a new Google Docs spreadsheet. I dont think the v2.0 .NET API can handle it natively (or if so I can't find the class/method), however It looks like the v3.0 protocol can but I'm not sure how to implement this in the current framework or even if it is possible with the current .net api. eg. ~DocumentsFeed.copy() (pseudo code).
Exporting to a temp excel file then uploading with a new name is not possible either as some of the complex formulas get messed up in the conversion process.
I am a bit of a .NET noob so any info would be greatly appreciated eg. How would I go about doing this in .NET if I could only use the v3 protocol (ajax etc) and not the .NET API.
Thanks
EDIT: (final class thanks to #langsamu for his help!)
using System;
using Google.GData.Documents;
using Google.GData.Client;
using Google.GData.Extensions;
public class GoogleDocument
{
private DocumentsService ds;
private String username;
private String password;
public GoogleDocument(String username, String password)
{
this.ds = new DocumentsService("doc service name");
this.username = username;
this.password = password;
this.ds.setUserCredentials(username, password);
this.ds.QueryClientLoginToken();
}
public void copyDocument(String oldFileName, String newFileName)
{
SpreadsheetQuery query = new Google.GData.Documents.SpreadsheetQuery();
query.Title = oldFileName;
query.TitleExact = true;
DocumentsFeed feed = this.ds.Query(query);
AtomEntry entry = feed.Entries[0];
entry.Title.Text = newFileName;
var feedUri = new Uri(DocumentsListQuery.documentsBaseUri);
this.ds.Insert(feedUri, entry);
}
}
Google.GData.Documents.DocumentsService service = new Google.GData.Documents.DocumentsService("YOUR_APPLICATIONS_NAME");
service.setUserCredentials("YOUR_USERNAME", "YOUR_PASSWORD");
Google.GData.Documents.SpreadsheetQuery query = new Google.GData.Documents.SpreadsheetQuery();
query.Title = "YOUR_SPREADSHEETS_TITLE";
query.TitleExact = true;
Google.GData.Documents.DocumentsFeed feed = service.Query(query);
Google.GData.Client.AtomEntry entry = feed.Entries[0];
var feedUri = new Uri(Google.GData.Documents.DocumentsListQuery.documentsBaseUri);
service.Insert(feedUri, entry);
This solution is basically about retrieving an existing spreadsheet (service.Query) using the Document List API and re-inserting it (service.Insert).
Make sure you replace the ALL CAPS application name, username, password and spreadsheet title.
Add a reference to Google.GData.Documents.
This is using .NET 4 (should work with lower versions as well) and Google Documents List Data API v2.0 (DLL says version is 1.6.0.0: google-gdata), which seems to use version 3.0 of the protocol.
It is a bit unclear if you are developing a web application or a desktop application, so I'll try and cover both (essentially they are very much alike - because...).
If you are developing a web application you won't be able to make a 100% AJAX solution. You will only be able to request URL's on the same domain. To do this you will need to either do the communication server side only, or do it server side and proxy it to your web app through AJAX.
If you are developing a desktop application you'll have to do this stuff aswell. Except the AJAX part.
An example app would be fairly easy - 2-3 hours work to whip up considering the documentation given. With just a little knowledge of HTTP and POST request forming you should be able to make it work.

Google Charts of SSL

I need to get the free Google charts working over SSL without any security errors. I am using c# and asp.net.
As Google charts does not support SSL by default, I am looking for a robust method of using there charts but ensuring my user doesn't get any security warnings over their browser.
One thought was to use a handler to call the charts api and then generate the output my site needs.
Similar to Pants are optional blog post. I haven't been able to get this example working at this stage.
Any suggestions, or samples are welcome.
Thanks
the Google Charts API is now available over HTTPS at via https at chart.googleapis.com.
Source: http://www.imperialviolet.org/2010/11/29/charthttps.html
We do this automatically in the NetQuarry Platform - it's pretty simple, although you do force the image to come through your site vs. charts.google.com, making your browser run the request through a single connection.
Since a chart is just a link to an image, what we do is to build the link to the chart (a much more complex process, obviously), then add the whole link to the query string on an internal handler (handler.ashx?req=chart& ). So the new link looks like this:
handler.ashx?act=chrt&req=chart&cht=p3&chs=450x170&chd=s:HAR9GBA&chl=New|In%20Progress|Responded|Won't%20Respond|On%20Hold|Future|Review|&chg=20,20,1,5&chg=10,25,1,5&chco=0A477D
Then, we simply download the image data and write it back as the response.
Here's the code:
Blockquote
private void GoogleChart(HttpContext cxt)
{
const string csPrefix = "?act=chrt&req=chart&";
HttpRequest req = cxt.Request;
HttpResponse rsp = cxt.Response;
string sUrl = cxt.Request.RawUrl;
int nStart = sUrl.IndexOf(csPrefix, StringComparison.OrdinalIgnoreCase);
rsp.Clear();
if (nStart > 0)
{
sUrl = "http://chart.apis.google.com/chart?" + sUrl.Substring(nStart + csPrefix.Length);
System.Net.WebClient wc = new System.Net.WebClient();
byte[] buffer = wc.DownloadData(sUrl);
cxt.Response.ClearContent();
cxt.Response.ClearHeaders();
cxt.Response.ContentType = "application/octet-stream";
cxt.Response.AppendHeader("content-length", buffer.Length.ToString());
cxt.Response.BinaryWrite(buffer);
}
}
I Have a partial solution that has one issue.
here is the link to my new post asking for help with a specific problem regarding my solution
My Attempt at a SSL handler

Categories

Resources