service
에 Google 드라이브를 사용하여 파일을 업로드하고 공유하는 앱을 개발하려고합니다. 그러나 문제는 공유 링크에 private
액세스 권한이 있다는 것입니다. 해당 액세스를 anyone with link
(으)로 변경하고 싶습니다. 달성하기 위해 나는 Google Drive REST API
을 사용하고 있지만 코드를 실행할 때 아무 일도 일어나지 않는 것 같습니다.Google API에 연결 백그라운드 서비스의 Java 클라이언트
public void changePermissionSettings(String resourceId) throws GeneralSecurityException, IOException, URISyntaxException {
com.google.api.services.drive.Drive driveService = getDriveService();
JsonBatchCallback<Permission> callback = new JsonBatchCallback<com.google.api.services.drive.model.Permission>() {
@Override
public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) throws IOException {
Log.e("upload", "Permission Setting failed");
}
@Override
public void onSuccess(com.google.api.services.drive.model.Permission permission, HttpHeaders responseHeaders) throws IOException {
Log.e("upload", "Permission Setting success");
}
};
final BatchRequest batchRequest = driveService.batch();
com.google.api.services.drive.model.Permission contactPermission = new com.google.api.services.drive.model.Permission()
.setType("anyone")
.setRole("reader");
driveService.permissions().create(resourceId, contactPermission)
.setFields("id")
.queue(batchRequest, callback);
new Thread(new Runnable() {
@Override
public void run() {
try {
batchRequest.execute();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
private com.google.api.services.drive.Drive getDriveService() throws GeneralSecurityException,
IOException, URISyntaxException {
Collection<String> elenco = new ArrayList<>();
elenco.add("https://www.googleapis.com/auth/drive");
GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(this, elenco)
.setSelectedAccountName(getAccountName());
return new com.google.api.services.drive.Drive.Builder(
AndroidHttp.newCompatibleTransport(), new JacksonFactory(), credential).build();
}
내가 여기에 두 가지 질문이 있습니다 : 여기 내 코드는
가 잘 함께 모두 구글 드라이브 안드로이드 API와 Google 드라이브 REST API를 사용할 수 있나요?
파일의 사용 권한 설정을 변경하는 방법
private
에서anyone with link
?? Documentation에 언급 된 내용은Authorization happens in response to receiving an error when sending a request.
입니다. 어떻게 실현할 수 있습니까?service
??