adding the code to fix the token request bug (grant_type missing)
Fixed the error with the request for the access token
Change the queries to a function, changed previous queries to http_build_query