繁体   English   中英

需要Google Cloud Print用户凭证

[英]Google Cloud Print User credentials required

我正在为我的(java)Web应用程序实现google cloud打印服务,我已经按照所有说明进行操作,但是仍然收到“需要凭据”作为响应。这是我的代码:

public static void main(String[] args) {
    HttpPost printPost = new HttpPost(
            "https://www.google.com/cloudprint/search?output=json");
    printPost.setHeader("Authorization",
            "GoogleLogin auth=" +getAccessToken());
    printPost.setHeader("scope",
            "https://www.googleapis.com/auth/cloudprint");
    printPost.setHeader("X-CloudPrint-Proxy", "printingTest");
    DefaultHttpClient httpclient = new DefaultHttpClient();
    try {
        HttpResponse printResponse = httpclient.execute(printPost);
        System.out.println(printResponse.getStatusLine());
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
public static String getAccessToken() {

    Credential credential = new GoogleCredential.Builder()
            .setTransport(new NetHttpTransport())
            .setJsonFactory(new JacksonFactory())
            .setClientSecrets(
                    "client_id",
                    "client_secret").build();
    try {
        credential
                .setRefreshToken("refresh_token");
        credential.refreshToken();
        return credential.getAccessToken();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;

}

这是一个简单的搜索命中。

在设置授权访问令牌时,在标题中使用“ Bearer”代替“ GoogleLogin auth =“

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM