<?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 Access Token in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Access-Token/m-p/366493#M20765</link>
    <description>&lt;P&gt;Is there Any way to generate Access Token without Authorization Code. Actually I was Implementing it in Salesforce without using Visual force Page.... And what is Expiration of the Access Token... Here is my&amp;nbsp; code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;public class DropboxController
{
//Fetched from URL
String code;
String accesstoken;
public DropboxController() {
code = ApexPages.currentPage().getParameters().get('code');
//Get the access token once we have code
if(code != '' &amp;amp;&amp;amp; code != null) {
AccessToken();
}
}

public PageReference DropAuth() {
//Authenticating
PageReference pg = new PageReference('https://www.dropbox.com/1/oauth2/authorize?response_type=code&amp;amp;client_id=&amp;lt;REDACTED&amp;gt;&amp;amp;redirect_uri=https://c.ap1.visual.force.com/apex/DropboxPage&amp;amp;state=Mytesting');
return pg;
}

public String AccessToken() {
//Getting access token from dropbox
String tokenuri = 'https://api.dropbox.com/1/oauth2/token?grant_type=authorization_code&amp;amp;code='+code+'&amp;amp;redirect_uri=https://c.ap1.visual.force.com/apex/DropboxPage';
HttpRequest req = new HttpRequest();
req.setEndpoint(tokenuri);
req.setMethod('POST');
req.setTimeout(60*1000);

Blob headerValue = Blob.valueOf('&amp;lt;REDACTED&amp;gt;' + ':' + '&amp;lt;REDACTED&amp;gt;');
String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);
Http h = new Http();
String resp;
HttpResponse res = h.send(req);
resp = res.getBody();

JSONParser parser = JSON.createParser(resp);
while (parser.nextToken() != null) {
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME)) {
String fieldName = parser.getText();
parser.nextToken();
if(fieldName == 'access_token') {
accesstoken = parser.getText();
}
}
}
//system.debug('accessToken = '+accessToken );
//System.debug(' You can parse the response to get the access token :: ' + resp);
string txtdata='';
try {
string data = 'https://content.dropboxapi.com/2/files/download';
HttpRequest re = new HttpRequest();
re.setEndpoint(data);
re.setHeader('Authorization' , 'Bearer ' +accesstoken);
re.setHeader('Dropbox-API-Arg', '{ "path":"/Test.txt" }');
re.setMethod('POST');
re.setTimeout(60000);
Http h2 = new Http();
HttpResponse res2 = h2.send(re);
system.debug('body-----&amp;gt;'+res2.getBody());
txtdata = res2.getBody();
}
catch(exception e) {
system.debug('error-----'+e.getMessage()+'line number---------&amp;gt;'+e.getLineNumber());
}
return txtdata;
}&amp;nbsp;&lt;/PRE&gt;</description>
    <pubDate>Mon, 23 Sep 2019 15:23:21 GMT</pubDate>
    <dc:creator>lonehero</dc:creator>
    <dc:date>2019-09-23T15:23:21Z</dc:date>
    <item>
      <title>Access Token</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Access-Token/m-p/366493#M20765</link>
      <description>&lt;P&gt;Is there Any way to generate Access Token without Authorization Code. Actually I was Implementing it in Salesforce without using Visual force Page.... And what is Expiration of the Access Token... Here is my&amp;nbsp; code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;public class DropboxController
{
//Fetched from URL
String code;
String accesstoken;
public DropboxController() {
code = ApexPages.currentPage().getParameters().get('code');
//Get the access token once we have code
if(code != '' &amp;amp;&amp;amp; code != null) {
AccessToken();
}
}

public PageReference DropAuth() {
//Authenticating
PageReference pg = new PageReference('https://www.dropbox.com/1/oauth2/authorize?response_type=code&amp;amp;client_id=&amp;lt;REDACTED&amp;gt;&amp;amp;redirect_uri=https://c.ap1.visual.force.com/apex/DropboxPage&amp;amp;state=Mytesting');
return pg;
}

public String AccessToken() {
//Getting access token from dropbox
String tokenuri = 'https://api.dropbox.com/1/oauth2/token?grant_type=authorization_code&amp;amp;code='+code+'&amp;amp;redirect_uri=https://c.ap1.visual.force.com/apex/DropboxPage';
HttpRequest req = new HttpRequest();
req.setEndpoint(tokenuri);
req.setMethod('POST');
req.setTimeout(60*1000);

Blob headerValue = Blob.valueOf('&amp;lt;REDACTED&amp;gt;' + ':' + '&amp;lt;REDACTED&amp;gt;');
String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);
Http h = new Http();
String resp;
HttpResponse res = h.send(req);
resp = res.getBody();

JSONParser parser = JSON.createParser(resp);
while (parser.nextToken() != null) {
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME)) {
String fieldName = parser.getText();
parser.nextToken();
if(fieldName == 'access_token') {
accesstoken = parser.getText();
}
}
}
//system.debug('accessToken = '+accessToken );
//System.debug(' You can parse the response to get the access token :: ' + resp);
string txtdata='';
try {
string data = 'https://content.dropboxapi.com/2/files/download';
HttpRequest re = new HttpRequest();
re.setEndpoint(data);
re.setHeader('Authorization' , 'Bearer ' +accesstoken);
re.setHeader('Dropbox-API-Arg', '{ "path":"/Test.txt" }');
re.setMethod('POST');
re.setTimeout(60000);
Http h2 = new Http();
HttpResponse res2 = h2.send(re);
system.debug('body-----&amp;gt;'+res2.getBody());
txtdata = res2.getBody();
}
catch(exception e) {
system.debug('error-----'+e.getMessage()+'line number---------&amp;gt;'+e.getLineNumber());
}
return txtdata;
}&amp;nbsp;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Sep 2019 15:23:21 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Access-Token/m-p/366493#M20765</guid>
      <dc:creator>lonehero</dc:creator>
      <dc:date>2019-09-23T15:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: Access Token</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Access-Token/m-p/366591#M20771</link>
      <description>&lt;P&gt;The&amp;nbsp;Dropbox API supports two different OAuth 2 authorization flows: "code" and "token". The code flow requires the use of an authorization code. The token flow does not. The token flow is generally meant for client-side applications though, and does require a redirect URI, where the access token is return on the URL fragment (and so not sent to the server). You can find more information on the two different flows in &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#oauth2-authorize" target="_self"&gt;the documentation&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Dropbox API access tokens do not expire by default, but they can be revoked by the user or app at any time.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2019 15:23:57 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Access-Token/m-p/366591#M20771</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2019-09-23T15:23:57Z</dc:date>
    </item>
  </channel>
</rss>

