Spotify Web API Console - c#

I am curious about how to get Json from a windows forms project and using a webBrowser control to simulate access to a spotify app. I know I need to pass a string of some kind such as clientid=.... etc
GET
https://accounts.spotify.com/authorize/?client_id=5fe01282e44241328a84e7c5cc169165&response_type=code&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&scope=user-read-private%20user-read-email&state=34fFs29kd09
How would I accomplish this using the code above?
Do I put it in string and send it off to a url using the webbrowser and some how get a response form the webpage???
Could someone show me some example to try and accomplish this?
I am very confused.
I don't know how to use the "GET" command or any of those cURL commands.
Another thing do I send the url to the webbrowser and have the response saved and try to seperate the Json that gets sent back?
Any help would be wonderful such as an explanation.
Ultimately I am just trying to get information on how to access my APP I created in spotify and which url to use so that a user can login to my app and they get a token to use the webapi or so that I can use the web api.
https://developer.spotify.com/web-api/authorization-guide/
I am lost. Help. Please.

Related

Using .Net how can I programmatically navigate to a webpage, interact with it via code, then get particular values from a newly generated page

I have a scenario where I would like to automate programmatically the following process:
Currently, I have to manually
Navigate to a webpage
Enter some text (an email) in a certain field on the webpage
Press the 'Search' button, which generates a new page containing a Table with the results on it.
Manually scroll through the generated results table and extract 4 pieces of information.
Is there a way for me to do this from a Desktop WPF App using C# ?
I am aware there is a WebClient type that can download a string, presumably of the content of the webpage, but I don't see how that would help me.
My knowledge of web based stuff is pretty non-existent so I am quite lost how to go about this, or even if this is possible.
I think a web driver is what you're looking for, I would suggest using Selenium, you can navigate to sites and send input or clicks to specific elements in them.
Well, I'll write the algorithm for you but you also need to some homework.
UseWebClient get the htm page with the form you want to auto fill and submit
Us regex and extract the action attribute of the form you want to auto submit. That gets you the URL you want to submit your next request to.
Since you know the fields in that form, create a class corresponding to those fields, let's call the class AutoClass
Create a new instance of your auto class and assign values you want to auto fill
Using WebClient to send your new request with the url you extracted from the form previously, attach your object which you want to send to the server either through serialization or any method.
Send the request and wait for feedback, then further action
Either use a web driver like Puppeteer (Selenium is kinda dead) or use HTTPS protocol to make web requests (if you don't get stopped by bot checks). I feel like your looking for the latter method because there is no reason to use a web driver in this case when a lighter method like HTTP requests can be used.
You can use RestSharp or the built in libraries if you want. Here is a popular thread of the ways to send requests with the libraries built in to C#.
To figure out what you need to send you should use a tool like Fiddler or Chrome Dev Tools (specifically the Network tab) to see what you need to send to acheive your goal as you would in a browser.

Automated login from C# Using Post in WPF

I've been trying to write an app to use OAUTH method with pInterest to Upload new pins automatically and have been trying to find the best way of doing this.
So Far i've got a working example going where in my WPF app in C# i can get the login details using a RestAPI Get Method to get the login URL for the pInterest user and once logged it my app will hit tab twice then enter to give permission from pInterest.
The Method i've got working involves -
Using .NET 4.6.2 or later getting WebView UI WPF controls from nuget
Using RestAPI Get Method to get the URL of the app accept page
Using the output of step 2 in a webview component to let IE login and display the App Accept Page ( IE having username / password set up already)
OnNavigateComplete once the URL has "/api.pinterest.com/oauth" using SendKeys.SendWait from Winforms to send Tab, Tab , Enter
Once Navigate completes grab the URL if its got "state" & "code" in the URL then close the form.
I'm looking to see if there is a better way of doing this i've tried CefSharp but the GetAuthorizeCreditials does not fire off when i implement my own IResponseHandler as its a Post Submit button and i've tried to use javascript code from C# passed in via cefSharp but i couldnt get it to work

WebRequest class to post data to login form

I want to use the WebRequest class to post data to a website. This works fine, however the website I'm posting to requires cookies/sessions (it's a login form). After logging in I need to retrieve some account information (this is information on a specific page).
How can I make sure the login information is being stored? In AutoIT I did this using a hidden webbrowser, however I want to use a console application for it.
My current code (to login) is too long to post here, so it can be found here.
Take a look at my aspx sessions scraper on bitbucket. It does exactly what you are asking for, including some aspx webforms specific extensions, like sending postbacks etc.
You need to store the cookie that you get after logging in and then send that cookie when you request pages containing personal information.
Here is an example of using cookies with WebRequest
It is possible that you can't connect because the session has ended so in this case you need to relogin.

how to create a win app which can interact with a website?

Hi
I'm trying to write a windows application which can read HTML content of a specific website and fill some data in some input fields and submit the page.
what I did untill now was reading page content from a WebBrowser object, navigated to the website.
I know that i need to create some request/response variables and work with them, but I have no good view on what i'm trying to do.
also, my information about HttpRequest and HttpResponse is so low...
HttpWebRequest is what you're looking for, examples for read/write to scrape abound.
WebClient might be simpler for you to implement but in the end is only a wrapper to the above.
You can try to use the approach described in the HttpWebRequest with https in C# thread as a starting point.

Obtaining Photos and Albums from Facebook using C#

I'm trying to parse through and obtain my (my personal account not my app) albums from Facebook using the Facebook C# SDK. My goal is to grab the 10-12 most recent photos on my account. However, I understand I have to grab the albums first.
So, I've tried numerous things and ended up with the following url which returns a 400 Bad Request:
https://graph.facebook.com/{my_user_id}/albums?access_token={my_access_token}
The token was obtained by calling:
https://graph.facebook.com/oauth/access_token?client_id={0}&client_secret={1}&grant_type={2}&scope={3}
Any ideas why I'd be getting the 400?
When using grant_type = client_credentials you're requesting the an app access token. This will allow you to do various administrative actions for your application. See App Login in http://developers.facebook.com/docs/authentication/.
However, when using the user-parts of the Graph Api you need to perform a User Login using the oAuth Dialog. There are different ways of doing this such as with the Javascript SDK which should be straightforward to use.
I've not found a nice way of doing this in a standalone web app using Facebook C# SDK without the Javascript SDK (it's easy in a canvas app using the CanvasAuthorize attribute).
Here's an example of how to do it i a WinForms app http://blog.prabir.me/post/Facebook-CSharp-SDK-Writing-your-first-Facebook-Application.aspx. It might work in a Asp.Net app if you could use the WebBrowser control. I've tried with WebClient but didn't have any luck.
Update
By looking at the sample here http://facebooksdk.codeplex.com/SourceControl/changeset/view/534da45e108f#Samples%2fCSMvcWebsite%2fControllers%2fHomeController.cs it looks like you should be able to use the FacebookAuthorize attribute in a standalone site.
Error code 400 means that the request was not correctly formatted. Verify that that the Final URL looks OK and try it in a browser.
The request could not be understood by
the server due to malformed syntax.
The client SHOULD NOT repeat the
request without modifications.
I.e. that you try the following https://graph.facebook.com/someuser/albums?access_token=1234 You would pre presented with the following:
{
"error": {
"type": "OAuthException",
"message": "Invalid OAuth access token."
}
}
If you provide an OK token and a real user, the result will probably look a bit different, but in your case you get a 400 because there is something wrong with the request.

Categories

Resources