Posts

Showing posts with the label WebRequest

Donate

Upload Photos Or Files To Google Photos Using Google Photos API, REST And C#.NET

Image
Good morning! I wrote a console application before Read Files From Google Photos Using Google Photos API, REST And C#.NET that reads media items from Google Photos using Google Photos API, C# And REST. That console application was the foundation to one of my project using real world client API. However, that project is limited to only read files and does not have the upload capabilities. Now that I'm free with the projects at work, it's time to revisit the Google Photos API and create a simple console application that will upload photos/images or files to Google Photos using REST, Google Photos API and C#. So to get started, make sure you have read the documentation to setup the API here Get started with REST . Once you have successfully setup the API, download the JSON file that contains your credentials specifically Client Secret and Client ID and add that file to your console app project. Make sure to set the Copy to Output Directory of the JSON file to Copy always i

Read Files From Google Photos Using Google Photos API, REST And VB.NET

Image
This is the VB.NET version of the post Read Files From Google Photos Using Google Photos API, REST and C#.NET . In your VB.NET project, you need to reference the Google.Apis.Auth package via NuGet and attach the JSON file that contains the Google API credentials. The models used for converting a JSON response to .NET object are shown below. Public Class clsResponseRootObject Public Property mediaItems As List( Of MediaItem) Public Property nextPageToken As String End Class Public Class MediaItem Public Property id As String Public Property productUrl As String Public Property baseUrl As String Public Property mimeType As String Public Property mediaMetadata As MediaMetadata Public Property filename As String End Class Public Class MediaMetadata Public Property creationTime As DateTime Public Property width As String Public Property height As String Public Property photo As Phot

Read Files From Google Photos Using Google Photos API, REST And C#.NET

Image
Related Tutorials On Google Photos API Read Files From Google Photos Using Google Photos API, REST and VB.NET Upload Photos, Images Or Files To Google Photos Using Google Photos API, Rest and C#.NET I've been working on a project last year to read and download images from Google Photos using the recent Google Photos API and C# as the programming language. During research, there was an existing .NET API called Picasa Web Albums API but has been deprecated and the docs suggested to migrate applications to the recent one. The examples in the current documentation provided are PHP, Java and REST API in which the example is written in Node.js. Since the requirement is to write a scheduled task or windows service in C#.NET, I decided to refresh my skills on sending requests to REST services using WebClient or HTTPWebRequest classes. To access media items, read or even download files using Google Photos API, you need to enable the Google Photos Library API, create a Google Proj

How To Post JSON Data With WebRequest In .NET

Hello, There was a question on how to post a JSON data using the WebRequest class on both C# and VB.NET given that using Ajax, the post data would look like this. data : '{ "age": "78", "weight": "51" }' In .NET, you need to store the JSON data into a string object and escape those double quotes before passing it to the WebRequest object. C#.NET string postData = "{ \"age\": \"78\", \"weight\": \"51\" }" ; VB.NET Dim postData As String = "{ ""age"": ""78"", ""weight"": ""51"" }" Cheers! :-)

CookieContainer - Part Of Cookie Is Invalid In C# Cookies And WebResponse

Given the code below when scraping a website, you might encounter an error which is stated in the title of the post that is Part Of Cookie Is Invalid . 1 2 3 4 5 6 7 8 9 10 11 WebRequest request = WebRequest.Create( "http://your_url_here" ); WebResponse webResponse = request.GetResponse(); if (webResponse.Headers[ "Set-Cookie" ] != null ) { Cookie m_ccCookies = new Cookie(); CookieContainer ccContainer = new CookieContainer(); ccContainer = new CookieContainer(); ccContainer.SetCookies(webResponse.ResponseUri, webResponse.Headers[ "Set-Cookie" ]); ccContainer.Add(ccContainer.GetCookies(webResponse.ResponseUri)); } The issue could be that the url domain cookie value which is passed to SetCookies method have unrecognized characters that needs to be encoded. So, the workaround is to encode the cookie value first and then assign the appropriate encoding before saving it to the cookie container object. 1 2 ccC

WebRequest Url Not Returning Correct Page Source If Proxynull Not Used As Part Of Url Query String (Web Scraping) In C#

In one of the sites im crawling, I encountered a situation where a site needs a query string like proxynull = 90B69303-3A61-4482-AF0725FDA1DAE548 or appended into a url like this http://samplesite/bin/jobs_list.cfm?proxynull=90B69303-3A61-4482-AF0725FDA1DAE548 I wonder if i could just use the post data and use the url without the proxynull query string like this http://samplesite/bin/jobs_list.cfm to scrape the website. After series of experimentation, the solution is to set the webproxy of the webrequest object to default proxy similar to the code below: ((HttpWebRequest)webRequest).Proxy = WebRequest.DefaultWebProxy; in order to use the url(http://samplesite/bin/jobs_list.cfm) without proxynull.

How To Get Or Retrieve The Response URL From WebRequest Object Using C#

The solution is to get the ResponseUri from the response object. //domain url: http://www.htcatalogs.com.au //response url: http://www.htcatalogs.com.au/2012/dailylistings/ WebRequest request = WebRequest.Create( "http://www.rmwilliams.com.au" ); HttpWebResponse resp = HttpWebResponse)request.GetResponse(); string ur = resp.ResponseUri.ToString(); Console.Write(ur);

Download File Using Webrequest With Credentials In C#

Here's a C# code that will download a file from source with credentials (password and username). This assumes that the source directory is password protected. HttpWebRequest request; HttpWebResponse response = null ; try { string username = "xxxuser" ; string password = "yyypass" ; NetworkCredential myCredentials = new NetworkCredential(username, password); request = (HttpWebRequest)WebRequest.Create(ListURL); request.Timeout = 900000000; request.Credentials = myCredentials; request.AllowWriteStreamBuffering = false ; response = (HttpWebResponse)request.GetResponse(); Stream s = response.GetResponseStream(); //Write to disk FileStream fs = new FileStream( "\\192.168.3.3\xmldata.xml" , FileMode.Create); byte []

Set JSON Response In Webrequest Class

To set the JSON response of a WebRequest class, assign the ContentType property of the WebRequest object to application/json; charset=utf-8 . req.ContentType = "application/json; charset=utf-8" ; Source: Stackoverflow

(502)Bad Gateway Returned From HttpWebRequest In C#

The solutions is to set the default proxy for the web request and assign user agent to it as shown below: ListURL = String.Format( "your_xml_feed_or_API_url_sample" ); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(ListURL); request.Timeout = 900000000; request.Proxy = HttpWebRequest.DefaultWebProxy; request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)" ; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream dataStream = response.GetResponseStream(); dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); ListingSource = reader.ReadToEnd(); ListingSource = System.Web.HttpUtility.HtmlDecode(ListingSource); Cheers!

The Error: 417 "Expectation Failed." During Webrequest In C#

Here's a solution on how to fix the 417 expectation failed error during WebRequest In C#. System.Net.ServicePointManager.Expect100Continue = false ;

Donate