久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

com.google.api.client.googleapis.json.GoogleJsonResponseExcep

com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden(com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden)
本文介紹了com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試將文本文件上傳到我的 Google 云端硬盤帳戶.無論如何,我總是遇到 com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden

I am trying to upload a text file to my Google Drive account. No matter what, I always encounter an com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden

Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
  "code" : 403,
  "errors" : [ {
    "domain" : "global",
    "message" : "Forbidden",
    "reason" : "forbidden"
  } ],
  "message" : "Forbidden"
}
    at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
    at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
    at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:423)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
    at chatterjee.sandeep.javabase.miscellaneous.DriveCommandLine.main(DriveCommandLine.java:69)

這是 DriveCommandLine.java

File file = service.files().insert(body, mediaContent).execute();

完整代碼:

import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse;
import com.google.api.client.http.FileContent;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.DriveScopes;
import com.google.api.services.drive.model.File;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class DriveCommandLine {

    private static String CLIENT_ID = "CLIENT_ID";
    private static String CLIENT_SECRET = "CLIENT_SECRET";

    private static String REDIRECT_URI = "REDIRECT_URI";

    public static void main(String[] args) throws IOException {
        HttpTransport httpTransport = new NetHttpTransport();
        JsonFactory jsonFactory = new JacksonFactory();

        GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
        httpTransport, jsonFactory, CLIENT_ID, CLIENT_SECRET,
        Arrays.asList(DriveScopes.DRIVE_FILE)).setAccessType("online")
        .setApprovalPrompt("auto").build();

        String url = flow.newAuthorizationUrl().setRedirectUri(REDIRECT_URI)
        .build();
        System.out
        .println("Please open the following URL in your browser then type the authorization code:");
        System.out.println("  " + url);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String code = br.readLine();

        GoogleTokenResponse response = flow.newTokenRequest(code)
        .setRedirectUri(REDIRECT_URI).execute();
        GoogleCredential credential = new GoogleCredential()
        .setFromTokenResponse(response);

        // Create a new authorized API client
        Drive service = new Drive.Builder(httpTransport, jsonFactory,
        credential).build();

        // Insert a file
        File body = new File();
        body.setTitle("My document");
        body.setDescription("A test document");
        body.setMimeType("text/plain");

        java.io.File fileContent = new java.io.File(
        "/path/to/TextFile.txt");
        FileContent mediaContent = new FileContent("text/plain", fileContent);

        File file = service.files().insert(body, mediaContent).execute();
        System.out.println("File ID: " + file.getId());
    }
}

我的項目構(gòu)建路徑中有以下 jar:

I have the following jars in my project build path:

commons-logging-1.1.1.jar
google-api-client-1.18.0-rc.jar
google-api-client-android-1.18.0-rc.jar
google-api-client-appengine-1.18.0-rc.jar
google-api-client-gson-1.18.0-rc.jar
google-api-client-jackson2-1.18.0-rc.jar
google-api-client-java6-1.18.0-rc.jar
google-api-client-servlet-1.18.0-rc.jar
google-api-services-drive-v1-rev123-1.18.0-rc.jar
google-http-client-1.18.0-rc.jar
google-http-client-android-1.18.0-rc.jar
google-http-client-appengine-1.18.0-rc.jar
google-http-client-gson-1.18.0-rc.jar
google-http-client-jackson2-1.18.0-rc.jar
google-http-client-jdo-1.18.0-rc.jar
google-oauth-client-1.18.0-rc.jar
google-oauth-client-appengine-1.18.0-rc.jar
google-oauth-client-java6-1.18.0-rc.jar
google-oauth-client-jetty-1.18.0-rc.jar
google-oauth-client-servlet-1.18.0-rc.jar
gson-2.1.jar
httpclient-4.0.3.jar
httpcore-4.0.1_1.jar
jackson-core-2.1.3.jar
jdo2-api-2.3-eb.jar
jetty-util-6.1.26.jar
jsr305-1.3.9.jar
transaction-api-1.1-rev-1.jar

目前我有兩個啟用 Drive API 的項目.

At present I have two projects set up with Drive API enabled.

現(xiàn)在我應該在哪里正確設置權(quán)限來解決這個問題?

Now where do I properly set up the permissions to resolve this issue?

另外,我在這里做錯了什么?

Also, what am I doing wrong here?

推薦答案

我遇到了同樣的問題,我做了以下更改并解決了問題

I had the same issue, I did the following change and it resolved the issue

1) 將 SheetsScopes.DRIVE 添加到要在 authorize() 中給出的范圍

1) Added SheetsScopes.DRIVE to the scopes to be given in authorize()

private static final List<String> SCOPES =
            Arrays.asList(SheetsScopes.SPREADSHEETS,SheetsScopes.DRIVE);

2) 創(chuàng)建了一個新目錄,這樣下次我運行它時,它會進行身份驗證并將憑據(jù)保存到新創(chuàng)建的目錄中

2) Created a new directory, so that next time I run it, it will authenticate and save the credential to the newly created directory

private static final java.io.File DATA_STORE_DIR = new java.io.File(
        System.getProperty("user.home"), ".credentials/2/sheets.googleapis.com-java-quickstart.json");

這篇關于com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

Upload progress listener not fired (Google drive API)(上傳進度偵聽器未觸發(fā)(Google 驅(qū)動器 API))
Save file in specific folder with Google Drive SDK(使用 Google Drive SDK 將文件保存在特定文件夾中)
Google Drive Android API - Invalid DriveId and Null ResourceId(Google Drive Android API - 無效的 DriveId 和 Null ResourceId)
Google drive api services account view uploaded files to google drive using java(谷歌驅(qū)動api服務賬戶查看上傳文件到谷歌驅(qū)動使用java)
Google Drive service account returns 403 usageLimits(Google Drive 服務帳號返回 403 usageLimits)
com.google.api.client.json.jackson.JacksonFactory; missing in Google Drive example(com.google.api.client.json.jackson.JacksonFactory;Google Drive 示例中缺少)
主站蜘蛛池模板: 91av免费版| 久久久日韩精品一区二区三区 | 国产一区二区在线播放 | 91tv在线观看| 日韩欧美中文 | 日韩精品在线观看网站 | 国产成人精品一区二区三区在线 | 亚洲成人在线免费 | 中文字幕四虎 | 色婷婷av99xx | 精品福利av导航 | 中国大陆高清aⅴ毛片 | 一区二区在线观看av | 欧美一级片在线看 | 久久宗合色 | 亚洲激情一区二区三区 | 日韩久久精品 | 久久人体视频 | 国产一区二区三区视频 | 日韩视频 中文字幕 | 99精品视频在线 | 日韩欧美国产一区二区三区 | 美女久久 | 国外成人在线视频 | 久久国内精品 | 久久中文一区二区 | av色站| 中文字幕日韩欧美一区二区三区 | 91精品国产777在线观看 | 国产一级久久久久 | 在线91| 精精国产xxxx视频在线 | 久久手机在线视频 | 国产精品a久久久久 | 日本二区在线观看 | 日韩欧美成人一区二区三区 | 国产精品日韩欧美一区二区三区 | 综合九九| 欧美精品一区二区三区在线播放 | www.788.com色淫免费 | 欧美精品久久久 |