Question

est-il possible de télécharger des images à l'aide d'URL SCRIBE-Java et Twitter Post URL "https://upload.twitter.com/1/statats/update_with_media.json"? ma source
Je reçois la réponse: {"Demande": "\ / 1 \ / statut \ / update_with_media.json", "erreur": "Impossible d'authentifier avec OAuth."}

Était-ce utile?

La solution

Juste pour aider quelqu'un d'autre en regardant cela, un moyen simple de construire la partie multiple est d'ajouter httpMime-4.0.1.jar et apache-mime4j-0.6.jar à votre chemin et procédez comme suit.

        /* You will have done this bit earlier to authorize the user

    OAuthService service = new ServiceBuilder().provider(TwitterApi.SSL.class).apiKey("[YOUR API KEY]").apiSecret("[YOUR SECRET]").callback("twitter://callback").build();
    Token accessToken = Do you oauth authorization as normal 

    */  

    OAuthRequest request = new OAuthRequest(Verb.POST, "https://upload.twitter.com/1/statuses/update_with_media.json");
    MultipartEntity entity = new MultipartEntity();
    try {

        entity.addPart("status", new StringBody("insert vacuous statement here"));
        entity.addPart("media", new FileBody(new File("/path/of/your/image/file")));

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        entity.writeTo(out);

        request.addPayload(out.toByteArray());
        request.addHeader(entity.getContentType().getName(), entity.getContentType().getValue());

        service.signRequest(accessToken, request);
        Response response = request.send();

        if (response.isSuccessful()) {
            // you're all good
        }

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

Le compromis ici est bien sûr ajouté la taille des 2 pots à votre apk

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top