Google Cloud Print User credentials required

…衆ロ難τιáo~ 提交于 2019-12-13 03:35:56

问题


I am implement google cloud print service for my (java) web application,I have followed all the instruction but still getting "Credentials required" in response.Here is my code :

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;

}

This is a simple search hit.


回答1:


use "Bearer " instead of "GoogleLogin auth=" in header while setting Authorization access token, also note the space with bearer it is important



来源:https://stackoverflow.com/questions/45279644/google-cloud-print-user-credentials-required

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!