Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
public function __construct(Dropbox $dropbox) { $this->api_client = $dropbox->api(); $this->content_client = $dropbox->content(); $this->access_token = session('access_token'); } public function dashboard() { return view('admin.dashboard'); } public function user(){ //dd($this->access_token); $response = $this->api_client->request('POST', '/2/users/get_current_account', [ 'headers' => [ 'Authorization' => 'Bearer ' . '$this->access_token' ] ]); $user = json_decode($response->getBody(), true); $page_data = [ 'user' => $user ]; return view('admin.user', $page_data); }
access_token returns null and yells error: Invalid authorization value in HTTP header "Authorization": "Bearer"
But when I hard code the access_token generated from the developers portal it works fine.
Is there a way to get the access token dynamically ?
Thanks in Advance
public function login(Request $request) { if ($request->has('code')) { $data = [ 'code' => $request->input('code'), 'grant_type' => 'authorization_code', 'client_id' => env('DROPBOX_APP_KEY'), 'client_secret' => env('DROPBOX_APP_SECRET'), 'redirect_uri' => env('DROPBOX_REDIRECT_URI') ]; $response = $this->api_client->request( 'POST', '/oauth2/token', ['form_params' => $data] ); $response_body = json_decode($response->getBody()->getContents(), true); $access_token = $response_body['access_token']; //dd($access_token); //I can access the token here return redirect('dashboard'); } return redirect('/'); }
public function user(){ $response = $this->adminRepo->apiClient->request('POST', '/2/users/get_current_account', [ 'headers' => [ 'Authorization' => 'Bearer ' . $this->adminRepo->accessToken ]
//error : invalid authorization value in HTTP header "Authorization": " (truncated...) ]); $user = json_decode($response->getBody(), true); $page_data = [ 'user' => $user ]; return view('admin.user', $page_data); }
Hey Greg, sorry about the post subject my bad.
Could you please take a look at above two methods in which I am trying to pass the access token generated by /oauth2/token but it returns null and throws an error of bad authorization header.Is there any possible way I can retrieve this token from within my other classes.
Thank you so much for your help. It means a lot me.
Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!