2

I am trying to connect to spotify API to get some data from my recently listened to tracks using this link "https://developer.spotify.com/console/get-recently-played/?limit=&after=&before=". In order to access this API, however, I need to generate an authentication code. I am unsure about how to incorporate this authentication token into my "GET" statement (or R code in general) in order to connect to the API. I am currently using the "HTTR" package in r to do this, not sure what I'm doing wrong. See my sample code below:

library(httr)
library(jsonlite) #for parsing the response could also use library(xml2)
library(dplyr)

user_id="xxxxxx"
Token="BQAPSJ4ckLLUCXZCyMl2_c0eiOrC0xV3oJLXP1eIABz8RJALGRMQ7-kIenzq_868Pt3bJPsIdGV753_QOv6F79-8XQVBnaEPXT93pDVXeId98m8RcH2_z37saM1QnMrmxmytTAr-bofPrZQ"

response = POST(
 'https://api.spotify.com/v1/me/player/recently-played',
  accept_json(),
  authenticate(user_id, Token), Authorization="bearer"
)

mytoken = content(response)$access_token
HeaderValue = paste0('Bearer ', mytoken)

The error I'm currently getting is https://api.spotify.com/v1/me/player/recently-played] Date: 2021-06-30 00:38 Status: 400 Content-Type: application/json Size: 99 B { "error": { "status": 400, "message": "Only valid bearer authentication supported" }

Thank you so much in advance for any help.

Phil
  • 7,287
  • 3
  • 36
  • 66
sal461
  • 19
  • 2
  • maybe try `GET("https://api.spotify.com/v1/me/player/recently-played", add_headers(Authorization=paste("Bearer", Token))` – chinsoon12 Jun 30 '21 at 05:04

0 Answers0