Sdk 是否有人成功地将Dropbox集成到Windows 8.1应用商店应用程序中,以及如何集成?
我有一个针对Windows 8.1的Windows应用商店应用程序,我需要集成Dropbox。到目前为止,还没有官方的Dropbox SDK。他们列出了一些选项。这些SDK中的一些已经多年没有被触及了,这令人不安 我还需要在不影响服务器的情况下进行身份验证。在iOS上,我通过让我的应用程序向操作系统注册一个自定义URI来实现这一点,这样在用户在浏览器中进行身份验证后,我的应用程序就可以通过令牌进行调用。也许Windows上需要类似的东西,但我找不到任何有人以这种方式设置身份验证的例子Sdk 是否有人成功地将Dropbox集成到Windows 8.1应用商店应用程序中,以及如何集成?,sdk,windows-store-apps,dropbox,dropbox-api,dropnet,Sdk,Windows Store Apps,Dropbox,Dropbox Api,Dropnet,我有一个针对Windows 8.1的Windows应用商店应用程序,我需要集成Dropbox。到目前为止,还没有官方的Dropbox SDK。他们列出了一些选项。这些SDK中的一些已经多年没有被触及了,这令人不安 我还需要在不影响服务器的情况下进行身份验证。在iOS上,我通过让我的应用程序向操作系统注册一个自定义URI来实现这一点,这样在用户在浏览器中进行身份验证后,我的应用程序就可以通过令牌进行调用。也许Windows上需要类似的东西,但我找不到任何有人以这种方式设置身份验证的例子 所以我的问
所以我的问题是:是否有人在没有单独服务器进行身份验证的情况下将Dropbox集成到Windows应用商店应用程序中,以及您是如何做到的?解决方案:我决定继续使用DropNetRT。我找不到一个完整的示例,说明如何在Windows应用商店应用程序中对其进行身份验证,但我最终找到了一个在没有服务器的情况下进行身份验证的完整解决方案,这是我的目标。我把它贴在这里,希望它能节省别人的时间
private const string VAULT_KEY_DROPBOX_CREDS = "com.mycompany.dropbox.creds";
private const string AppKey = "myappkey";
private const string AppSecret = "myappsecret";
static private string UserToken = null;
static private string UserSecret = null;
static public DropNetClient Client = null;
static private bool IsLoggedIn = false;
public static async Task<bool> Authorize()
{
if (!IsLoggedIn)
{
// first try to retrieve credentials from the PasswordVault
PasswordVault vault = new PasswordVault();
PasswordCredential savedCreds = null;
try
{
savedCreds = vault.FindAllByResource(VAULT_KEY_DROPBOX_CREDS).FirstOrDefault();
}
catch (Exception)
{
// this happens when no credentials have been stored
}
if (savedCreds != null)
{
savedCreds.RetrievePassword();
UserToken = savedCreds.UserName;
UserSecret = savedCreds.Password;
// since credentials were found in PasswordVault, they can be used to create an authorized client immediately
Client = new DropNetClient(AppKey, AppSecret, UserToken, UserSecret);
IsLoggedIn = true;
}
else
{
// no credentials were found in PasswordVault, so we need for the user to authenticate
// start with a shell of a DropNetClient
Client = new DropNetClient(AppKey, AppSecret);
// build a request uri so the user can authenticate, and configure it to return control to the app when complete
UserLogin requestToken = await Client.GetRequestToken();
Uri appCallbackUri = WebAuthenticationBroker.GetCurrentApplicationCallbackUri();
string requestUrlString = Client.BuildAuthorizeUrl(requestToken, appCallbackUri.ToString());
Uri requestUri = new Uri(requestUrlString);
// this call presents the standard Windows "Connecting to a service" screen to let the user authenticate
// then returns control once the user either authenticates or cancels (uses the back arrow button)
WebAuthenticationResult war = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, requestUri, null);
string authCode = null;
string uid = null;
if (war.ResponseStatus == WebAuthenticationStatus.Success)
{
// the user successfully authorized the app to use Dropbox, but we are still not done
// parse the oauth_token and uid out of the response (although the uid is not needed for anything)
string response = war.ResponseData;
WwwFormUrlDecoder decoder = new WwwFormUrlDecoder(new Uri(response).Query);
authCode = decoder.GetFirstValueByName("oauth_token");
uid = decoder.GetFirstValueByName("uid");
if (authCode != null)
{
// update the DropNetClient with the authCode and secret
// the secret does not change during authentication so just use the one from the requestToken
Client.SetUserToken(authCode, requestToken.Secret);
// this is the last step: getting a final access token
UserLogin finalAccessToken = await Client.GetAccessToken();
// now that we have full credentials, save them in the PasswordVault
// so that the user will not need to authenticate the next time
if (finalAccessToken != null)
{
UserToken = finalAccessToken.Token;
UserSecret = finalAccessToken.Secret;
vault.Add(new PasswordCredential(VAULT_KEY_DROPBOX_CREDS, UserToken, UserSecret));
}
IsLoggedIn = true;
}
}
}
}
return IsLoggedIn;
}
public static void Deauthorize()
{
// to deauthorize dropbox, we just have to find any saved credentials and delete them
PasswordVault vault = new PasswordVault();
try
{
PasswordCredential savedCreds = vault.FindAllByResource(VAULT_KEY_DROPBOX_CREDS).FirstOrDefault();
vault.Remove(savedCreds);
}
catch (Exception)
{
// this happens when no credentials have been stored
}
IsLoggedIn = false;
}
private const string VAULT\u KEY\u DROPBOX\u CREDS=“com.mycompany.DROPBOX.CREDS”;
私有常量字符串AppKey=“myappkey”;
私有常量字符串AppSecret=“myappsecret”;
静态私有字符串UserToken=null;
静态私有字符串UserSecret=null;
静态公共DropNetClient客户端=null;
静态私有bool IsLoggedIn=false;
公共静态异步任务授权()
{
如果(!IsLoggedIn)
{
//首先尝试从PasswordVault检索凭据
PasswordVault=新的PasswordVault();
PasswordCredential savedCreds=null;
尝试
{
savedCreds=vault.FindAllByResource(vault\u KEY\u DROPBOX\u CREDS).FirstOrDefault();
}
捕获(例外)
{
//如果未存储任何凭据,则会发生这种情况
}
if(savedCreds!=null)
{
savedCreds.RetrievePassword();
UserToken=savedCreds.UserName;
UserSecret=savedCreds.Password;
//由于凭据是在PasswordVault中找到的,因此可以使用它们立即创建授权客户端
客户端=新的DropNetClient(AppKey、AppSecret、UserToken、UserSecret);
IsLoggedIn=真;
}
其他的
{
//在PasswordVault中未找到凭据,因此我们需要用户进行身份验证
//从DropNetClient的外壳开始
客户端=新的DropNetClient(AppKey,AppSecret);
//构建一个请求uri,以便用户可以进行身份验证,并将其配置为在完成时将控制权返回给应用程序
UserLogin requestToken=wait Client.GetRequestToken();
Uri appCallbackUri=WebAuthenticationBroker.GetCurrentApplicationCallbackUri();
string requestUrlString=Client.BuildAuthorizeUrl(requestToken,appCallbackUri.ToString());
Uri requestUri=新Uri(requestUrlString);
//此调用显示标准的Windows“连接到服务”屏幕,以便用户进行身份验证
//然后在用户验证或取消后返回控制(使用后退箭头按钮)
WebAuthenticationResult war=等待WebAuthenticationBroker.AuthenticationAsync(WebAuthenticationOptions.None,requestUri,null);
字符串authCode=null;
字符串uid=null;
if(war.ResponseStatus==WebAuthenticationStatus.Success)
{
//用户成功授权应用程序使用Dropbox,但我们仍然没有完成
//从响应中解析oauth_标记和uid(尽管任何事情都不需要uid)
字符串响应=war.ResponseData;
WwwFormUrlDecoder=新的WwwFormUrlDecoder(新Uri(response).Query);
authCode=decoder.GetFirstValueByName(“oauth_令牌”);
uid=decoder.GetFirstValueByName(“uid”);
if(authCode!=null)
{
//使用authCode和secret更新DropNetClient
//该秘密在身份验证期间不会更改,因此只需使用requestToken中的一个
SetUserToken(authCode,requestToken.Secret);
//这是最后一步:获取最终访问令牌
UserLogin finalAccessToken=wait Client.GetAccessToken();
//现在我们有了完整的凭据,请将它们保存在PasswordVault中
//这样用户下次就不需要进行身份验证了
if(finalAccessToken!=null)
{
UserToken=finalAccessToken.Token;
UserSecret=finalAccessToken.Secret;
添加(新密码凭证(vault\u KEY\u DROPBOX\u CREDS、UserToken、UserSecret));
}
IsLoggedIn=真;
}
}
}
}
返回伊斯洛格丁;
}
公共静态无效取消授权()
{
//要取消dropbox的授权,我们只需找到任何保存的凭据并将其删除
PasswordVault=新的PasswordVault();
尝试
{
PasswordCredential savedCreds=vault.FindAllByResource(vault\u KEY\u DROPBOX\u CREDS).FirstOrDefault();
vault.Remove(保存红色);
}
捕获(例外)
{
//如果未存储任何凭据,则会发生这种情况
}
IsLoggedIn=false;
}
你看过吗?哇,没有,谢谢@smarx!不知怎么的,我错过了。这似乎使身份验证部分变得简单。然后我仍然需要一种方法来实际检索文件夹元数据、创建文件夹、上载/下载文件和删除文件。我目前正在调查DropNet(),因为我想要一个比其他调用更高级别的API,而且我不相信有官方的Dropbox SDK