我正在开发一个Android应用程序,它使用gdata-java-client下载文档仅供显示.到目前为止,我有一个应用程序,它使用服务进行身份验证并显示用户文档列表.当用户选择文档时,对文档本身进行另一个查询.对txt,html,rtf和doc文件的请求很有效,但是当我以.csv或.xsl格式请求电子表格时,结果是意外的.
我正在使用HTTPResponse对象来存储HTTPRequest的结果.当我以.csv或.xsl格式请求文档时,HTTPResponse.parseAsString()方法会生成一个完整的html页面,该页面似乎是Google Docs主页.听起来很奇怪,但结果是登录页面的实际html.HTTPResponse.getStatusMessage返回200.
好像我在这里错过了一些简单的东西.是否有HTTPResponse的另一个属性包含.csv数据?
我很确定我使用正确的uri来下载电子表格,因为它可以在我通过浏览器下载时使用.在任何情况下,这是一个例子uri:
https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=0AsE_6_YIr797dHBTUWlHMUFXeTV4ZzJlUGxWRnJXanc&exportFormat=csv
Run Code Online (Sandbox Code Playgroud)
在此先感谢任何帮助:)
java android google-api-java-client google-drive-android-api google-sheets-api
在测试SO 22295903中讨论的删除,垃圾功能时,我遇到了这个问题.
1 /创建包含内容的文件
GoogleApiClient _gac;
DriveFile createFileWait(DriveFolder fldr, String name, String mime, byte[] buff) {
DriveFile drvFile = null;
try {
ContentsResult rslt = Drive.DriveApi.newContents(_gac).await();
if (rslt.getStatus().isSuccess()) {
Contents cont = rslt.getContents();
cont.getOutputStream().write(buff);
MetadataChangeSet meta = (mime == null) ?
new MetadataChangeSet.Builder().setTitle(name).build() :
new MetadataChangeSet.Builder().setTitle(name).setMimeType(mime).build();
drvFile = fldr.createFile(_gac, meta, cont).await().getDriveFile();
}
} catch (Exception e) {}
return drvFile;
}
Run Code Online (Sandbox Code Playgroud)
2 /使用查询检索文件(它的标题):
ArrayList<DriveId> findAll(String title, String mime, DriveFolder fldr) {
ArrayList<DriveId> dIDs = null;
if (isConnected()) …Run Code Online (Sandbox Code Playgroud) 自从新的 Google Drive Android Api (GDAA) 推出以来,这个问题一直困扰着我。首先在这里讨论,我希望它会在以后的版本中消失,但它仍然存在(截至 2014/03/19)。用户删除的(指“drive.google.com”中的“删除”操作)文件/文件夹不断出现在
Drive.DriveApi.query(_gac, query), and
DriveFolder.queryChildren(_gac, query)
Run Code Online (Sandbox Code Playgroud)
也
DriveFolder.listChildren(_gac)
Run Code Online (Sandbox Code Playgroud)
方法,即使与
Filters.eq(SearchableField.TRASHED, false)
Run Code Online (Sandbox Code Playgroud)
查询限定符,或者如果我对结果使用过滤构造
for (Metadata md : result.getMetadataBuffer()) {
if ((md == null) || (!md.isDataValid()) || md.isTrashed()) continue;
dMDs.add(new DrvMD(md));
}
Run Code Online (Sandbox Code Playgroud)
使用
Drive.DriveApi.requestSync(_gac);
Run Code Online (Sandbox Code Playgroud)
没有影响。自移除以来经过的时间变化很大,我的最后一个案例超过 12 小时。它是完全随机的。
更糟糕的是,我什至不能依赖“drive.google.com”中的 EMPTY TRASH,它不会产生任何可预测的结果。有时文件状态更改为“isTrashed()”,有时它会从结果列表中消失。
当我不断摆弄这个问题时,我最终得到了以下超级骇客:
find file with TRASH status equal FALSE
if (file found and is not trashed) {
try to write content
if ( write content fails)
create a new file
}
Run Code Online (Sandbox Code Playgroud)
甚至这也无济于事。即使文件在垃圾箱中,该文件也显示为健康(并且它的状态被查询和元数据测试双重过滤)。它甚至可以愉快地写入并在垃圾箱中检查时进行修改。
这里的结论是修复应该获得更高的优先级,因为它使 Drive …
我正在使用Google Drive Android API(作为Google Play服务的一部分)将文件上传到云端.
要连接客户端,我使用以下代码(简化):
apiClient = new GoogleApiClient.Builder(context)
.addApi(Drive.API)
.setAccountName(preferences.getString("GOOGLE_DRIVE_ACCOUNT", null))
.build();
ConnectionResult connectionResult = apiClient.blockingConnect(SERVICES_CONNECTION_TIMEOUT_SEC, TimeUnit.SECONDS);
if (!connectionResult.isSuccess()) {
throw new ApiConnectionException(); //our own exception
}
Run Code Online (Sandbox Code Playgroud)
要上传文件我正在使用以下代码(简化):
DriveApi.ContentsResult result = Drive.DriveApi.newContents(apiClient).await();
if (!result.getStatus().isSuccess()) {
/* ... code for error handling ... */
return;
}
OutputStream output = result.getContents().getOutputStream();
/* ... writing to output ... */
//create actual file on Google Drive
DriveFolder.DriveFileResult driveFileResult = Drive.DriveApi
.getFolder(apiClient, folderId)
.createFile(apiClient, metadataChangeSet, result.getContents())
.await();
Run Code Online (Sandbox Code Playgroud)
除了一个特定的用户案例外,一切都按预期工作.当用户从"已连接的应用"中删除我们的应用时(使用Google设置应用),此代码仍会返回所有调用的成功结果.虽然文件永远不会上传到Google云端硬盘.
与Google Play服务的连接也会成功.
它是API的错误还是以某种方式检测到用户断开了应用程序?
我正在创建一个应用程序,我正在将Google Drive Android API集成到其中.我有一个主要活动,然后打开一个片段,导致谷歌驱动器.但是,当我尝试登录时(无论是什么gmail帐户,我都尝试过现有的,创建新的,无论如何)我得到ConnectionResult错误代码17 SIGN_IN_FAILED.该应用已在开发者控制台中获得授权,并且已启用Drive API.我不知道还能做什么.
这是相关代码:
public class FileSharingFragment extends Fragment implements
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
mGoogleApiClient.connect();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_file_sharing, container, false);
users = (TextView) rootView.findViewById(R.id.users);
getActivity().setTitle("Files");
return rootView;
}
@Override
public void onActivityResult(int requestCode, int resultCode,
Intent data) …Run Code Online (Sandbox Code Playgroud) android google-drive-api android-studio google-drive-android-api
我想使用Google Drive API for Android列出用户云端硬盘的Root文件夹中的所有文件.
我尝试过的:
使用SCOPE_FILE和listChildren:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
Run Code Online (Sandbox Code Playgroud)然后列出文件:
Drive.DriveApi.getRootFolder(mGoogleApiClient)
.listChildren(mGoogleApiClient)
.setResultCallback(new ResultCallback<DriveApi.MetadataBufferResult>() {
@Override
public void onResult(DriveApi.MetadataBufferResult result) {
if (!result.getStatus().isSuccess()) {
Log.v("DKDK", "Request failed");
return;
}
MetadataBuffer metadataBuffer = result.getMetadataBuffer(); // empty!
}
}
Run Code Online (Sandbox Code Playgroud)
我发现是SCOPE_FILE只列出由应用程序,并不是所有的文件被创建的文件.
使用https://www.googleapis.com/auth/drive范围
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(new Scope("https://www.googleapis.com/auth/drive"))
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
Run Code Online (Sandbox Code Playgroud)失败,例外:
com.google.android.gms.drive.auth.c: Authorization failed: Unsupported scope: https://www.googleapis.com/auth/drive
at com.google.android.gms.drive.auth.g.a(SourceFile:86)
at com.google.android.gms.drive.api.e.<init>(SourceFile:230)
at com.google.android.gms.drive.api.a.q.a(SourceFile:71)
at …Run Code Online (Sandbox Code Playgroud) 我正在尝试将我的应用程序连接到Google Play服务以访问Google云端硬盘,但它显示我与statusCode的连接失败SIGN_IN_REQUIRED.
但它似乎就在3天前表现得那样.我也检查了谷歌的开发者控制台.他们可能在API中改变了一些我无法弄清楚的东西.欢迎您的帮助.
我的代码:
/**
* Create a new file and save it to Drive.
*/
private void saveFileToDrive(final byte[] data) {
// Start by creating a new contents, and setting a callback.
Log.i(TAG, "Creating new contents.");
//final Bitmap image = mBitmapToSave;
Drive.DriveApi.newDriveContents(mGoogleApiClient)
.setResultCallback(new ResultCallback<DriveApi.DriveContentsResult>() {
@Override
public void onResult(DriveApi.DriveContentsResult result) {
// If the operation was not successful, we cannot do anything
// and must
// fail.
if (!result.getStatus().isSuccess()) {
Log.i(TAG, "Failed to create new contents.");
return; …Run Code Online (Sandbox Code Playgroud) android google-api google-api-client google-drive-android-api android-googleapiclient
我正在开发一个Android应用程序,它需要将某些键值数据保存到云中.因此,当用户安装我的应用程序时,我可以从云中恢复键值数据.我做了很多研究,包括Android BackupAgent API,它根本不稳定.我已经做过一些关于使用Google Drive Android SDK的研究,它确实可以成功备份和恢复键值数据.但它需要用户互动才能选择哪个帐户,即使我的设备只添加了一个Google帐户,并且之前已授权该应用访问Google Drive SDK.
我希望通过有限的用户交互尽可能无缝且自动地完成整个过程,备份和恢复.我注意到WhatsApp Android可以实现这样的功能.但我未能在Google Drive SDK 示例中查找示例.
是否有任何样本可以自动演示数据恢复,而无需选择像WhatsApp Android这样的Google帐户?任何指导将不胜感激.
我想将相机中的照片直接上传到驱动器文件夹中:
OutputStream outputStream = result.getDriveContents().getOutputStream();
ByteArrayOutputStream bitmapStream = new ByteArrayOutputStream();
/* image is my Bitmap */
image.compress(Bitmap.CompressFormat.PNG, 100, bitmapStream);
try {
outputStream.write(bitmapStream.toByteArray());
} catch (IOException e1) {
Log.i(TAG, "Unable to write file contents.");
}
Run Code Online (Sandbox Code Playgroud)
所以我这样做,它的工作.问题是我在驱动器中的图片质量很差,我需要一个高质量的视频.
我已经尝试过这个解决方案将位图转换为byteArray android
但随后在驱动器中,照片无法识别为媒体文件,无法读取.我可能失败了.
编辑:我究竟做了同样的事情,是有/sf/answers/910054211/,做这种办法让我的位图ActivityResult:
try {
mBitmapToSave = MediaStore.Images.Media.getBitmap(this.getContentResolver(), data.getData());
} catch (IOException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud) 我正在使用此https://developers.google.com/drive/android/auth#connecting_and_authorizing_the_google_drive_android_api中显示的代码
在我的应用程序中,我单击以连接到驱动器,但它导致此行正在执行
connectionResult.startResolutionForResult(this, 1);
Run Code Online (Sandbox Code Playgroud)
由于连接失败.
然后它会打开一个帐户菜单供我选择帐户.当我点击它然后对话框解除,我仍然无法连接到谷歌驱动器,因为每次结果代码为0
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
switch (requestCode) {
case 1:
if (resultCode == RESULT_OK) {
mGoogleApiClient.connect();
}
break;
}
}
Run Code Online (Sandbox Code Playgroud)
我会假设代码是正确的,但有人知道我需要做什么来防止取消?我相信我为OA Auth正确设置了我的凭据
google-drive-api google-play-services google-drive-android-api