需要Google Cloud Print用户凭证 [英] Google Cloud Print User credentials required
本文介绍了需要Google Cloud Print用户凭证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为我的(java)Web应用程序实现google cloud打印服务,我已按照所有说明进行操作,但仍然收到需要凭据"作为回应.这是我的代码:
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.
推荐答案
在设置授权访问令牌时,在标头中使用承载"而不是"GoogleLogin auth =,还请注意带有承载的空间很重要
use "Bearer " instead of "GoogleLogin auth=" in header while setting Authorization access token, also note the space with bearer it is important
这篇关于需要Google Cloud Print用户凭证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文