【问题标题】:Account Authorization for Google Drive ApiGoogle Drive Api 的帐户授权
【发布时间】:2013-02-11 21:52:48
【问题描述】:

我正在开发一个有潜力提供大量统计信息的安卓应用程序。我想将这些数据保存在我的谷歌驱动器上以供以后分析。

但是,我是 Google api 的新手,几乎不知道如何以编程方式授权我的帐户。这是我目前所拥有的。

private static Uri driveUri;
private static Drive service;
private GoogleAccountCredential credential;
private Account driveAccount;

//      AccountManager accManager = 
//              (AccountManager) getSystemService(Context.ACCOUNT_SERVICE);
//      accManager.setUserData(driveAccount, ???, ???)



    credential = GoogleAccountCredential.usingOAuth2(this, DriveScopes.DRIVE);
    credential.setSelectedAccountName("myaccount@gmail.com");

    service = getDriveService(credential);

public class UploadToDrive extends AsyncTask<String, Void, String> {

    @Override
    protected String doInBackground(String... arg0) {
        // TODO Auto-generated method stub
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date());
        File sdcard = new File(Environment.getExternalStorageDirectory().getPath());
        File fileAnalytics = null;
        try {
            fileAnalytics = File.createTempFile("Sessions" + File.separator + "session_" + timeStamp, ".txt", sdcard);
        } catch (IOException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
        }

        PrintStream ps = null;
        try {
            ps = new PrintStream(fileAnalytics);
        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        ps.println("Count: " + count);
        ps.println("Time: " + (System.currentTimeMillis() - startTime));
        ps.close();
        FileContent content = new FileContent("text/plain", fileAnalytics);

        com.google.api.services.drive.model.File body = new com.google.api.services.drive.model.File();
        body.setTitle(fileAnalytics.getName());
        body.setMimeType("text/plain");


        try {
            service.files().insert(body, content);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return null;
    }

    @Override
    protected void onProgressUpdate(Void... values) {
        // TODO Auto-generated method stub
        super.onProgressUpdate(values);
    }


}

代码运行成功,文件已在设备上创建,但我想将其发送到我的谷歌驱动器。

我认为主要问题是我不知道帐户 name 凭据应该是什么。我有一种感觉,它不是“myacc@gmail.com”。有什么方法可以获取我自己的 google 帐户的帐户名称字符串?

【问题讨论】:

    标签: android google-drive-api google-account


    【解决方案1】:

    问题似乎在于 Google Drive、Dropbox 和其他云服务没有内置支持访问您自己的帐户。

    即使我确实得到了我的帐户密钥,它也会每 15 分钟更改一次!

    我建议建立一个网站并使用 FTP 上传文件。

    【讨论】:

      猜你喜欢
      • 2019-07-27
      • 1970-01-01
      • 2019-02-03
      • 2015-12-26
      • 1970-01-01
      • 2018-07-11
      • 1970-01-01
      • 2013-08-21
      • 2012-10-26
      相关资源
      最近更新 更多