久久久久久久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的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我正在嘗試將文本文件上傳到我的 Google 云端硬盤帳戶.無(wú)論如何,我總是遇到 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());
    }
}

我的項(xiàng)目構(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

目前我有兩個(gè)啟用 Drive API 的項(xiàng)目.

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

現(xiàn)在我應(yīng)該在哪里正確設(shè)置權(quán)限來(lái)解決這個(gè)問(wèn)題?

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

另外,我在這里做錯(cuò)了什么?

Also, what am I doing wrong here?

推薦答案

我遇到了同樣的問(wèn)題,我做了以下更改并解決了問(wèn)題

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)建了一個(gè)新目錄,這樣下次我運(yùn)行它時(shí),它會(huì)進(jìn)行身份驗(yàn)證并將憑據(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");

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

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

相關(guān)文檔推薦

Upload progress listener not fired (Google drive API)(上傳進(jìn)度偵聽器未觸發(fā)(Google 驅(qū)動(dòng)器 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 - 無(wú)效的 DriveId 和 Null ResourceId)
Google drive api services account view uploaded files to google drive using java(谷歌驅(qū)動(dòng)api服務(wù)賬戶查看上傳文件到谷歌驅(qū)動(dòng)使用java)
Google Drive service account returns 403 usageLimits(Google Drive 服務(wù)帳號(hào)返回 403 usageLimits)
com.google.api.client.json.jackson.JacksonFactory; missing in Google Drive example(com.google.api.client.json.jackson.JacksonFactory;Google Drive 示例中缺少)
主站蜘蛛池模板: 欧美日韩久久 | 久久99精品视频 | 日韩精品激情 | 亚州一区二区三区 | 九九热精品在线 | 久久久久一区 | 久久精品男人的天堂 | 精品国产青草久久久久96 | 一区二区免费视频 | 国产精品黄视频 | 免费观看的av毛片的网站 | 久久免费精彩视频 | av手机免费在线观看 | 亚洲一区二区三区高清 | 国产精品中文字幕在线观看 | 国产高潮av| 日韩国产欧美一区 | 精品视频免费 | 蜜桃av鲁一鲁一鲁一鲁 | 久草资源网站 | 久久精彩视频 | 99精品欧美一区二区三区综合在线 | 狠狠婷婷综合久久久久久妖精 | 中文字幕在线不卡 | 久久精品高清视频 | 丁香婷婷在线视频 | 在线免费观看黄色 | 麻豆久久久| 国产精品一区二区三区在线 | 欧美日韩国产在线观看 | 日韩国产在线观看 | av在线二区 | 天天av综合 | 国产一区二区影院 | 精品国产乱码久久久久久蜜柚 | 99re在线视频 | 色视频在线免费观看 | 偷拍第一页 | 在线视频h | 日韩av免费在线观看 | 久久精品免费一区二区三 |