Pregunta

¿Es posible cargar imágenes usando Scribe-Java y Twitter Publicar URL "https://upload.twitter.com/1/statuses/update_with_media.json"?
mi fuente
Recibo la respuesta: {"Solicitud": "\ / 1 \ / ESTADOS \ / update_with_media.json", "Error": "No se pudo autenticarse con OAuth".}

¿Fue útil?

Solución

Solo para ayudar a alguien más que mira esto, una forma sencilla de construir la multifunción es agregar httpmime-4.0.1.jar y apache-mime4j-0.6.jar a su camino y hacer lo siguiente.

        /* 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();
    }

El comercio aquí es, por supuesto, agregando el tamaño de los 2 tarros a su APK

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top