首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >要求Google云打印用户凭据

要求Google云打印用户凭据
EN

Stack Overflow用户
提问于 2017-07-24 11:37:56
回答 1查看 594关注 0票数 0

我正在为我的(java) web应用程序实现google服务,我遵循了所有的指令,但在response.Here中仍然获得“所需的凭据”是我的代码:

代码语言:javascript
复制
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;

}

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-25 09:49:32

在设置授权访问令牌时,在头中使用"GoogleLogin auth=“而不是”auth=“,还请注意带承载的空格是很重要的

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45279644

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档