<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Expired Access Token in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Expired-Access-Token/m-p/603978#M28053</link>
    <description>&lt;P&gt;Thanks! I see that ticket was automatically closed after some time because you didn't reply to the message with a question we sent on June 7. Did you receive that message? If so, please reply to that by email to re-open that with support. Otherwise, you can open &lt;A href="https://www.dropbox.com/developers/contact" target="_blank"&gt;a new one here&lt;/A&gt;. Either way, please share the rest of the requested information so we can investigate.&lt;/P&gt;</description>
    <pubDate>Fri, 17 Jun 2022 15:59:12 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2022-06-17T15:59:12Z</dc:date>
    <item>
      <title>Expired Access Token</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Expired-Access-Token/m-p/603900#M28049</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm currently working on Dropbox API to upload a backup file (.tar.gz) of 25GB - 27GB. Earlier the dropbox API was working fine with the long-lived access token.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below are the steps which I have followed to upload a backup file in chunks of 4194304&lt;/P&gt;
&lt;P&gt;1. Generate Access and Refresh Token using dropbox oauth2/token&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#oauth2-token" target="_blank" rel="noopener"&gt;https://www.dropbox.com/developers/documentation/http/documentation#oauth2-token&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Starting the upload session by calling the /upload_session/start&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-start" target="_blank" rel="noopener"&gt;https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-start&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Appending the backup file to the upload session in chunks of 4194304&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-append" target="_blank" rel="noopener"&gt;https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-append&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The upload usually completes after 5-7hrs, due to the short-lived token the upload process is interrupted after 4hrs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The curl call made to /upload_session/append after 4hrs is throwing an expired_access_token error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried to renew the access token, using the below API after receiving the expired_access_token error in the curl call:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#oauth2-token" target="_blank" rel="noopener"&gt;https://www.dropbox.com/developers/documentation/http/documentation#oauth2-token&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The access token was successfully renewed and tried to resume the upload by providing the access token to upload_append API.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After the curl call made to upload_appened API, I now receive a "500 error page" and am unable to continue the upload process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Need help for me to complete the backup process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;how to proceed with uploading a backup file that takes more than 4hrs to complete.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2022 12:20:40 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Expired-Access-Token/m-p/603900#M28049</guid>
      <dc:creator>DloadJunior</dc:creator>
      <dc:date>2022-06-17T12:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: Expired Access Token</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Expired-Access-Token/m-p/603965#M28051</link>
      <description>&lt;P&gt;The upload process should continue to work the same way even once you switch to a new short-lived access token. A 500 error would indicate something went wrong on the server though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, can you double check you're still only sending 4194304 bytes per request on the requests that fail?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, I'll need to look into this further, but I'd need some more information. In that case, please reply with:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;the name and version number of the platform and SDK/library you are using, if any&lt;/LI&gt;
&lt;LI&gt;the steps to reproduce the issue, including relevant code snippet(s) and parameter value(s), but don't include any access or refresh token(s)&lt;/LI&gt;
&lt;LI&gt;the affected account ID(s)&lt;/LI&gt;
&lt;LI&gt;a sample of the unexpected error/output, including response headers&lt;/LI&gt;
&lt;LI&gt;whether or not the request succeeds if you retry it&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Feel free to &lt;A href="https://www.dropbox.com/developers/contact" target="_blank"&gt;open an API ticket&lt;/A&gt; if you'd prefer to share privately.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2022 15:18:39 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Expired-Access-Token/m-p/603965#M28051</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2022-06-17T15:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: Expired Access Token</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Expired-Access-Token/m-p/603975#M28052</link>
      <description>&lt;P&gt;Hi &lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/10"&gt;@Greg-DB&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your quick response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;the name and version number of the platform and SDK/library you are using, if any&lt;/P&gt;&lt;P&gt;I'm not using SDK/library, I have made a curl function to send/receive the data from Dropbox API. I'm using the PHP Stream Wrapper class to upload and download the backup file. Below is the code snippet of the curl function&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="php"&gt;function __curl($url, $headers = '', $filepointer = '', $upload_size = 0, $post = '', $download_file = '', $ignore_errors = 0, $retry = false){
		global $error, $l;
		
		// Set the curl parameters.
		$ch = curl_init($url);
		
		if(!empty($headers)){
			curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
		}
		
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
		
		if(!empty($filepointer)){
			curl_setopt($ch, CURLOPT_PUT, true);
			curl_setopt($ch, CURLOPT_INFILE, $filepointer);
			curl_setopt($ch, CURLOPT_INFILESIZE, $upload_size);
		}
		
		if(!empty($post)){
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
		}
		//curl_setopt($ch, CURLOPT_VERBOSE, TRUE);

		// Turn off the server and peer verification (TrustManager Concept).
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		
		if(!empty($download_file)){
			curl_setopt($ch, CURLOPT_FILE, $download_file);
		}
		
		// Get response from the server.
		$resp = curl_exec($ch);
		
		echo '&amp;lt;br /&amp;gt;Resp: ';
		r_print($resp);
		echo '&amp;lt;br /&amp;gt;Curl Error:';
		$curl_error = curl_error($ch);
		echo $curl_error;
		$errno = curl_errno($ch);
		r_print($errno);
		$error_message = curl_strerror($errno);
		r_print($error_message);
		
		$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
		curl_close($ch);
		echo "HTTP_CODE: ".$http_code;
		
		$result = json_decode($resp, true);
		r_print($result);

		
		if(!empty($result['error']) &amp;amp;&amp;amp; empty($ignore_errors)){
			if($result['error']['.tag'] == 'invalid_access_token'){
				$error[$result['error']['.tag']] = $l['invalid_access_token'];
			}elseif($result['error']['.tag'] == 'incorrect_offset'){
				$error[$result['error']['.tag']] = 'Incorrect Offset';
			}elseif($result['error'][$result['error']['.tag']]['.tag'] == 'insufficient_space'){
				$error[$result['error'][$result['error']['.tag']]['.tag']] = $l['insufficient_space'];
			}elseif(!empty($result['error'][$result['error']['.tag']]['.tag'])){
				$error[] = $result['error'][$result['error']['.tag']]['.tag'];
			}else{
				$error[$result['error']['.tag']] = $result['error']['.tag'];
			}
			
			return false;
		}
		
		return $result;
	}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="php"&gt;function stream_write($data){
		global $error;
		
		if(!is_resource($this-&amp;gt;wp)){
			$this-&amp;gt;wp = fopen($this-&amp;gt;tpfile, 'w+');
		}
		
		//Initially store the data in a memory
		fwrite($this-&amp;gt;wp, $data);		
		$this-&amp;gt;tmpsize += strlen($data);
		$data_size = strlen($data);
		
		// Are we already more than 4 MB ?
		if($this-&amp;gt;tmpsize &amp;gt;= 4194304){
			
			rewind($this-&amp;gt;wp);
			
			//Call upload append function to write the data from PHP Memory stream to Dropbox
			$this-&amp;gt;upload_append($this-&amp;gt;session_id, $this-&amp;gt;wp, $this-&amp;gt;tmpsize);
			
			// Close the temp file and reset the variables
			fclose($this-&amp;gt;wp);
			$this-&amp;gt;wp = NULL;
			$this-&amp;gt;tmpsize = 0;
		}
		
		return $data_size;	
	}

// Dropbox API to upload
	function upload_append($session_id, $filep, $data_size){
		global $error;
		
		$args = json_encode(array('cursor' =&amp;gt; array('session_id' =&amp;gt; $session_id, 
											'offset' =&amp;gt; $this-&amp;gt;offset), 
								'close' =&amp;gt; false));
		
		$upload_url = 'https://content.dropboxapi.com/2/files/upload_session/append_v2';
		$headers = array('Authorization: Bearer '.$this-&amp;gt;access_token,
						'Dropbox-API-Arg: '.$args,
						'Content-Type: application/octet-stream');
		
		$resp = $this-&amp;gt;__curl($upload_url, $headers, $filep, $data_size);
		
		if(is_null($resp)){
			$this-&amp;gt;offset += $data_size;
			return $data_size;
		}
		
		return false;
		
	}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;the steps to reproduce the issue, including relevant code snippet(s) and parameter value(s), but don't include any access or refresh token(s)&lt;/P&gt;&lt;P&gt;I guess the issue can be reproduced by uploading a file large in chunks of 4MB which could take more than 4hrs to complete&lt;/P&gt;&lt;P&gt;I have previously opened a ticket, in which you can find the error I'm receiving, below is the ticket id for the same:&lt;/P&gt;&lt;P&gt;Ticket #17124496&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Awaiting your response.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2022 15:44:13 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Expired-Access-Token/m-p/603975#M28052</guid>
      <dc:creator>DloadJunior</dc:creator>
      <dc:date>2022-06-17T15:44:13Z</dc:date>
    </item>
    <item>
      <title>Re: Expired Access Token</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Expired-Access-Token/m-p/603978#M28053</link>
      <description>&lt;P&gt;Thanks! I see that ticket was automatically closed after some time because you didn't reply to the message with a question we sent on June 7. Did you receive that message? If so, please reply to that by email to re-open that with support. Otherwise, you can open &lt;A href="https://www.dropbox.com/developers/contact" target="_blank"&gt;a new one here&lt;/A&gt;. Either way, please share the rest of the requested information so we can investigate.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2022 15:59:12 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Expired-Access-Token/m-p/603978#M28053</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2022-06-17T15:59:12Z</dc:date>
    </item>
  </channel>
</rss>

