Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
因此,当我将代码部署到CloudBees global.java时,';t运行(播放框架2.1)_Java_Playframework_Google Api_Playframework 2.1_Cloudbees - Fatal编程技术网

因此,当我将代码部署到CloudBees global.java时,';t运行(播放框架2.1)

因此,当我将代码部署到CloudBees global.java时,';t运行(播放框架2.1),java,playframework,google-api,playframework-2.1,cloudbees,Java,Playframework,Google Api,Playframework 2.1,Cloudbees,我只是在玩弄google drive api(云存储)并弄清楚它是如何工作的,我在play framework中编写了一些代码,其中在global.java onStart中获得了对驱动器的访问,并向驱动器写入了测试文档。在本地,这可以正常工作,但当我将代码部署到新的CloudBees应用程序并访问该应用程序时,我在日志中会出现此错误,我就是不知道如何调试它: Play server process ID is 7454 Oops, cannot start the server. @6eone

我只是在玩弄google drive api(云存储)并弄清楚它是如何工作的,我在play framework中编写了一些代码,其中在global.java onStart中获得了对驱动器的访问,并向驱动器写入了测试文档。在本地,这可以正常工作,但当我将代码部署到新的CloudBees应用程序并访问该应用程序时,我在日志中会出现此错误,我就是不知道如何调试它:

Play server process ID is 7454
Oops, cannot start the server.
@6eonea90e: Cannot init the Global object
    at play.api.WithDefaultGlobal$$anonfun$play$api$WithDefaultGlobal$$globalInstance$1.apply(Application.scala:57)
    at play.api.WithDefaultGlobal$$anonfun$play$api$WithDefaultGlobal$$globalInstance$1.apply(Application.scala:51)
    at play.utils.Threads$.withContextClassLoader(Threads.scala:18)
    at play.api.WithDefaultGlobal$class.play$api$WithDefaultGlobal$$globalInstance(Application.scala:50)
    at play.api.DefaultApplication.play$api$WithDefaultGlobal$$globalInstance$lzycompute(Application.scala:383)
    at play.api.DefaultApplication.play$api$WithDefaultGlobal$$globalInstance(Application.scala:383)
    at play.api.WithDefaultGlobal$class.global(Application.scala:66)

这是Global.java的代码:

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.jackson.JacksonFactory;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.DriveScopes;
import com.google.api.services.drive.model.File;
import com.google.api.services.drive.Drive.Files;
import com.google.api.services.drive.model.FileList;

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

import play.*;
import play.Logger;

public class Global extends GlobalSettings {

    private static String CLIENT_ID = "595172328396-l4kpto8ip9fpaea0k2987eeq8f42bged.apps.googleusercontent.com";
    private static String CLIENT_SECRET = "EvTUvAodjGx2eW_d3k8oy8Fb";

    private static String REDIRECT_URI = "urn:ietf:wg:oauth:2.0:oob";

    @Override
    public void onStart(Application app) {    try{
        Logger.info("Application has started");

        HttpTransport httpTransport = new NetHttpTransport();
        JsonFactory jsonFactory = new JacksonFactory();

        GoogleCredential credential = new GoogleCredential.Builder()
                .setClientSecrets(CLIENT_ID, CLIENT_SECRET)
                .setJsonFactory(jsonFactory).setTransport(httpTransport).build()
                .setRefreshToken("1/MZ4GTNA_HMbOcKDSqp6ymSd11dlkgxoMXxfWwhwMJRg").setAccessToken("ya29.AHES6ZQk7NDC-OCba7_yANc_uqWPLwDLl95TlT_DXgkLqrr6qmyLRw");;




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

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

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

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

        Logger.info("List of stuff: " + service.children().toString());

        Logger.info("File ID: " + file.getId());    }catch (IOException ex) {}
    }
}

谷歌访问令牌只能使用1小时。看起来您并不是在用刷新令牌请求访问令牌。。。相反,您似乎正在设置一个已经发布的版本

您需要请求获取访问令牌(使用刷新令牌)


有趣的是,一旦您使用刷新令牌生成一个新的访问令牌,旧的令牌就会失效。。。或者至少这是我发现的经验…

是的,我也在某个地方读到过,但现在(上次测试10小时后),我仍然可以在本地无错误地运行代码,获取访问权限并创建测试文档。另外,我现在所做的显然是错误的,我不知道为什么它会起作用,以供以后使用。您能用纯java中的刷新令牌获取新的访问令牌吗?因为我只能找到一个javascript示例。是的,你可以在纯java中得到它。。。嗯,可能是您的客户端id“类型”错误。。。设计用于通过JavaScript从网页使用的刷新令牌与服务器使用的不同(更长),并且可能与您的IPWait绑定,因此对于桌面应用程序(我的案例),刷新令牌与我的IP绑定?这可以解释为什么我的代码在部署时停止工作。