Dropbox Authentication In Salesforce - Easy Setup (Authentication Part 1)

本文提供了一步一步的指南,说明如何在Salesforce中集成Dropbox,包括创建帐户、生成应用密钥和秘密、配置Visual Force页面、替换代码中的值以及设置远程站点设置,最终实现与Dropbox的双向数据交换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

From log time managing data is a big deal, and a lot are concerned with it. Multiple options are available to handle this, out of them Dropbox, Box.com, Amazon are the main ones.

In this blog Authentication with Dropbox is explained so developers can get started.

Step 1  : Create an account on  Dropbox , then go to  this link  and create an app. It will create "App Key" and "App Secret" which we will be using in Salesforce. Leave the OAuth2 section blank for now.


Step 2  : Go to salesforce and create this apex class (DropboxController) :

  1. public class DropboxController  
  2. {  
  3.     //Fetched from URL  
  4.     String code ;  
  5.       
  6.     public DropboxController()  
  7.     {  
  8.         code = ApexPages.currentPage().getParameters().get('code') ;  
  9.         //Get the access token once we have code  
  10.         if(code != '' && code != null)  
  11.         {  
  12.             AccessToken() ;  
  13.         }  
  14.     }  
  15.       
  16.     public PageReference DropAuth()  
  17.     {  
  18.         //Authenticating  
  19.         PageReference pg = new PageReference('https://www.dropbox.com/1/oauth2/authorize?response_type=code&client_id=vaabb5qz4jv28t5&redirect_uri=https://c.ap1.visual.force.com/apex/DropboxPage&state=Mytesting') ;  
  20.         return pg ;  
  21.     }  
  22.       
  23.     public void AccessToken()  
  24.     {  
  25.         //Getting access token from dropbox  
  26.         String tokenuri = 'https://api.dropbox.com/1/oauth2/token?grant_type=authorization_code&code='+code+'&redirect_uri=https://c.ap1.visual.force.com/apex/DropboxPage';   
  27.         HttpRequest req = new HttpRequest();  
  28.         req.setEndpoint(tokenuri);  
  29.         req.setMethod('POST');  
  30.         req.setTimeout(60*1000);  
  31.             
  32.         Blob headerValue = Blob.valueOf('vaabb5qz4jv28t5' + ':' + 'dpmmll522bep6pt');  
  33.         String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);  
  34.         req.setHeader('Authorization', authorizationHeader);  
  35.         Http h = new Http();  
  36.         String resp;  
  37.         HttpResponse res = h.send(req);  
  38.         resp = res.getBody();  
  39.           
  40.         System.debug(' You can parse the response to get the access token ::: ' + resp);  
  41.    }  
  42. }  


Step 3  : Now create visualforce page (DropboxPage) :

  1. <apex:page controller="DropboxController">  
  2. <apex:form>  
  3.     <apex:pageblock>  
  4.         <apex:commandbutton action="{!DropAuth}" value="Dropbox Authentication">  
  5.     </apex:commandbutton></apex:pageblock>  
  6. </apex:form>  
  7. </apex:page>  


Step 4  : Replace the code with your values

1 . As you can see we have this in code :

  1. PageReference pg = new PageReference('https://www.dropbox.com/1/oauth2/authorize?response_type=code&client_id=vaabb5qz4jv28t5&redirect_uri=https://c.ap1.visual.force.com/apex/DropboxPage&state=Mytesting') ;  


You have to replace "client_id" with your "App Key" (redirect_uri is the complete page URL which we've just created). Now as visualforce page is created you can fill the OAuth2 section as shown in the screenshot above in dropbox.

2. Replace " dpmmll522bep6pt " in this line 
  1. Blob headerValue = Blob.valueOf('vaabb5qz4jv28t5' + ':' + 'dpmmll522bep6pt');  
with you "App Secret" 

Step 5  : Don't forget to set the remote site settings for dropbox



Now all set to go. Open the page "https:// ..... /apex/DropboxPage" and hit "Dropbox Authentication". In the debug you will get the access token which you can further use to hit Dropbox APIs.

Please note, code is not beautified as this is just to explain how you can authenticate dropbox with salesforce. A lot more creativity can be applied here.

From here everything is set and you are ready to hit the dropbox API and fetch the data or store the data. Complete documentation is  here .
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值