Spotify.NET/16b2da92.8ad66bd5.js

1 line
13 KiB
JavaScript
Raw Normal View History

(window.webpackJsonp=window.webpackJsonp||[]).push([[8],{136:function(e,n,t){"use strict";t.r(n),t.d(n,"frontMatter",(function(){return o})),t.d(n,"metadata",(function(){return s})),t.d(n,"rightToc",(function(){return p})),t.d(n,"default",(function(){return c}));var a=t(2),r=t(9),i=(t(0),t(188)),o={id:"5_to_6",title:"5.x.x to 6.x.x"},s={id:"5_to_6",title:"5.x.x to 6.x.x",description:"SpotifyAPI.Web",source:"@site/docs/5_to_6.md",permalink:"/SpotifyAPI-NET/docs/next/5_to_6",editUrl:"https://github.com/JohnnyCrazy/SpotifyAPI-NET/edit/master/SpotifyAPI.Docs/docs/5_to_6.md",version:"next",lastUpdatedBy:"L0um15",lastUpdatedAt:1607089956,sidebar:"docs",previous:{title:"UWP",permalink:"/SpotifyAPI-NET/docs/next/example_uwp"}},p=[{value:"SpotifyAPI.Web",id:"spotifyapiweb",children:[{value:"Initialization",id:"initialization",children:[]},{value:"Proxy",id:"proxy",children:[]},{value:"Calling API Endpoints",id:"calling-api-endpoints",children:[]},{value:"Error/Header Handling",id:"errorheader-handling",children:[]}]},{value:"SpotifyAPI.Web.Auth",id:"spotifyapiwebauth",children:[{value:"Authorization Code Auth",id:"authorization-code-auth",children:[]}]}],l={rightToc:p};function c(e){var n=e.components,t=Object(r.a)(e,["components"]);return Object(i.b)("wrapper",Object(a.a)({},l,t,{components:n,mdxType:"MDXLayout"}),Object(i.b)("h2",{id:"spotifyapiweb"},"SpotifyAPI.Web"),Object(i.b)("h3",{id:"initialization"},"Initialization"),Object(i.b)("p",null,"In ",Object(i.b)("inlineCode",{parentName:"p"},"5.x"),", a new ",Object(i.b)("inlineCode",{parentName:"p"},"SpotifyWebAPI")," instance could be created without supplying necessary values, since they were implemented as properties. With ",Object(i.b)("inlineCode",{parentName:"p"},"6.x"),", necessary values have to be given in the constructor and ",Object(i.b)("inlineCode",{parentName:"p"},"SpotifyWebAPI")," has been renamed to ",Object(i.b)("inlineCode",{parentName:"p"},"SpotifyClient"),". Also, ",Object(i.b)("inlineCode",{parentName:"p"},"SpotifyClientConfig")," has been introduced to give a better configuration experience, including retry handlers, automatic authenticators and proxy configurations."),Object(i.b)("pre",null,Object(i.b)("code",Object(a.a)({parentName:"pre"},{className:"language-csharp"}),'// OLD\nvar spotify = new SpotifyWebAPI { AccessToken = "YourAccessToken" };\nvar spotify = new SpotifyWebAPI(ProxyConfig); // No access token - invalid\n\n// NEW\nvar spotify = new SpotifyClient("YourAccessToken");\n\nvar config = SpotifyClientConfig\n .CreateDefault()\n .WithToken("YourAccessToken");\nvar spotify = new SpotifyClient(config);\n\nvar config = SpotifyClientConfig\n .CreateDefault()\n .WithAuthenticator(new ClientCredentialsAuthenticator(CLIENT_ID, CLIENT_SECRET)); // takes care of access tokens\nvar spotify = new SpotifyClient(config);\n')),Object(i.b)("p",null,"For some performance guides, have a look at the ",Object(i.b)("a",Object(a.a)({parentName:"p"},{href:"/SpotifyAPI-NET/docs/next/configuration"}),"Configuration Guide")),Object(i.b)("h3",{id:"proxy"},"Proxy"),Object(i.b)("p",null,"In ",Object(i.b)("inlineCode",{parentName:"p"},"5.x"),", the proxy configuration could be passed to the ",Object(i.b)("inlineCode",{parentName:"p"},"SpotifyWebAPI")," constructor. In ",Object(i.b)("inlineCode",{parentName:"p"},"6.x"),", they're part of the HTTP Client. The built-in http client supports proxies out of the box:"),Object(i.b)("pre",null,Object(i.b)("code",Object(a.a)({parentName:"pre"},{className:"language-csharp"}),'var httpClient = new NetHttpClient(new ProxyConfig("localhost", 8080)\n{\n User = "",\n Password = "",\n SkipSSLCheck = false,\n});\nvar config = SpotifyClientConfig\n .CreateDefault()\n .WithHTTPClient(httpClient);\n\nvar spotify = new SpotifyClient(config);\n')),Object(i.b)("h3",{id:"calling-api-endpoints"},"Calling API Endpoints"),Object(i.b)("p",null,"In ",Object(i.b)("inlineCode",{parentName:"p"},"5.x"),", there was one big instance to support all API endpoints. Parameters to these endpoints were passed directly as method parameters. Optional par