2017-07-24 3 views
0

Je suis mettre en œuvre un service d'impression en nuage Google pour mon application web (java), j'ai suivi toutes les instructions, mais toujours obtenir "pouvoirs nécessaires" dans response.Here est mon code:Google Cloud Print informations d'identification utilisateur requis

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; 

} 

Ceci est un résultat de recherche simple.

Répondre

0

utilisation « Bearer » au lieu de « GoogleLogin auth = » en-tête lors de la configuration jeton d'accès d'autorisation, notez l'espace avec porteur il est important