从Android上传图片到tumblr API

17

我原以为使用Tumblr API上传图片会很容易,但实际上并不是这样。(编辑现在已经容易了,请看本条目末尾的编辑2

我的应用程序应该将一张图片上传到tumblr。我更喜欢从服务中完成这个任务,但现在我使用一个活动来完成上传,上传完成后活动就关闭了。在OnCreate()中,用户被认证:

consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);

// It uses this signature by default
// consumer.setMessageSigner(new HmacSha1MessageSigner());

provider = new CommonsHttpOAuthProvider(REQUEST_TOKEN_URL,ACCESS_TOKEN_URL,AUTH_URL);

String authUrl;
try 
{
authUrl = provider.retrieveRequestToken(consumer, CALLBACK_URL);
Log.d(TAG, "Auth url:" + authUrl);

startActivity(new Intent("android.intent.action.VIEW", Uri.parse(authUrl)));

} 

这会打开一个浏览器活动,用户可以在其中添加用户名和密码,然后应用程序返回到活动(这也是我必须使用活动的原因,我不知道如何从服务中执行此操作)。
从浏览器返回后,数据被提取:
Uri uri = context.getIntent().getData();
if (uri != null && uri.toString().startsWith(CALLBACK_URL)) 
{  
    Log.d(TAG, "uri!=null");
    String verifier = uri.getQueryParameter("oauth_verifier");  
    Log.d(TAG, "verifier"+verifier);
    try 
    {
        provider.setOAuth10a(true);
        provider.retrieveAccessToken(consumer, verifier);
        Log.d(TAG, "try");
    } 
    catch (Exception e) 
    {
        Log.e(TAG, e.toString());
        e.printStackTrace();
    } 
OAUTH_TOKEN = consumer.getToken();
OAUTH_SECRET = consumer.getTokenSecret();

这两个片段大部分是我从这里获得的,它们运行良好。

有了这些令牌,我现在可以尝试在tumblr上放置数据。当我尝试添加文本时,使用以下方法可以正常工作:

private void createText()
{
    if(!OAUTH_TOKEN.equals(""))
    {

        HttpContext context = new BasicHttpContext();
        HttpPost request = new HttpPost("http://api.tumblr.com/v2/blog/" + blogname + ".tumblr.com/post");

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("type", "text")); 
        nameValuePairs.add(new BasicNameValuePair("body", "this is just a test"));  

        try 
        {
        request.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        } 
        catch (UnsupportedEncodingException e1) 
        {
            Log.e(TAG, e1.toString());
            e1.printStackTrace();
        }

        if (consumer == null)
        {
            consumer = new CommonsHttpOAuthConsumer(OAuthConstants.TUMBR_CONSUMERKEY, OAuthConstants.TUMBR_SECRETKEY);
        }
        if (OAUTH_TOKEN == null || OAUTH_SECRET == null)
        {
            Log.e(TAG, "Not logged in error");
        }
        consumer.setTokenWithSecret(OAUTH_TOKEN, OAUTH_SECRET);

        try 
        {
            consumer.sign(request);
        } 
        catch (OAuthMessageSignerException e) 
        {

        } 
        catch (OAuthExpectationFailedException e) 
        {
        } 
        catch (OAuthCommunicationException e) 
        {
        }
        HttpClient client = new DefaultHttpClient();
        //finally execute this request
        try 
        {
            HttpResponse response = client.execute(request, context);
            HttpEntity responseEntity = response.getEntity(); 
            if (responseEntity != null) 
            { 
                Log.d(TAG, "responseEntety!=null");
                try 
                {
                    Log.d(TAG, EntityUtils.toString(responseEntity));
                } 
                catch (ParseException e) 
                {
                    e.printStackTrace();
                    Log.e(TAG, e.toString());
                } 
                catch (IOException e) 
                {
                    e.printStackTrace();
                    Log.e(TAG, e.toString());
                } // gives me {"meta":{"status":401,"msg":"Not Authorized"},"response":[]} when I try to upload a photo
            }
            else
            {
                Log.d(TAG, "responseEntety==null");
            }
        } 
        catch (ClientProtocolException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
        catch (IOException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    PostToTumblr.this.finish();
}

正如您在这里所看到的http://www.tumblr.com/blog/snapnowandroid(至少目前是这样),文本“this is just a test”已发布。

然而,当我尝试发布图片时,出现了奇怪的情况。现在我已经查过了,显然这是Tumblr API的一个众所周知的问题,已经在这里进行了广泛讨论,并且有些人已经在其他编程语言中解决了这个问题(例如这里),但我一直无法重复那些成功。

该方法的结构与上述可行的方法完全相同,只是nameValuePairs不同。

该方法接收一个名为photo的Bitmap变量:

    private void uploadToTumblr(Bitmap photo)

这个位图被转换成了一个数组:

ByteArrayOutputStream stream = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] bytes = stream.toByteArray();

nameValuePairs被填充如下:
nameValuePairs.add(new BasicNameValuePair(URLEncoder.encode("type", enc), URLEncoder.encode("photo", enc)));
nameValuePairs.add(new BasicNameValuePair(URLEncoder.encode("caption", enc), URLEncoder.encode(text, enc))); 
nameValuePairs.add(new BasicNameValuePair("data", Base64.encodeToString(bytes, Base64.URL_SAFE))); 

这是从tumblr api返回的结果:{"meta":{"status":400,"msg":"Bad Request"},"response":{"errors":["Error uploading photo."]}}

我已经按照this article中所述以不同方式对图片进行编码,但没有任何变化。

//http://www.coderanch.com/t/526487/java/java/Java-Byte-Hex-String
final char[] hexArray = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
char[] hexChars = new char[bytes.length * 3];
int v;
for ( int j = 0; j < bytes.length; j++ ) 
{
    v = bytes[j] & 0xFF;
    hexChars[j * 3] = '%';
    hexChars[j * 3 + 1] = hexArray[v >>> 4];
    hexChars[j * 3 + 2] = hexArray[v & 0x0F];
}
String s = new String(hexChars);                
s = URLEncoder.encode(s, enc);
nameValuePairs.add(new BasicNameValuePair(URLEncoder.encode("data", enc), s)); 

这里是完整的方法(不包括十六进制编码):
private void uploadToTumblr(Bitmap photo)
{
    if(!OAUTH_TOKEN.equals(""))
    {

        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        photo.compress(Bitmap.CompressFormat.PNG, 100, stream);
        byte[] bytes = stream.toByteArray();

        String text ="SNAP";


        HttpContext context = new BasicHttpContext();
        HttpPost request = new HttpPost("http://api.tumblr.com/v2/blog/" + blogname + ".tumblr.com/post");

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); 
        String enc = "UTF-8"; 

        try 
        {
            nameValuePairs.add(new BasicNameValuePair(URLEncoder.encode("type", enc), URLEncoder.encode("photo", enc)));
            nameValuePairs.add(new BasicNameValuePair(URLEncoder.encode("caption", enc), URLEncoder.encode(text, enc))); 
            nameValuePairs.add(new BasicNameValuePair("data", Base64.encodeToString(bytes, Base64.URL_SAFE))); 
        } 
        catch (UnsupportedEncodingException e2) 
        {
            Log.e(TAG, e2.toString());
            e2.printStackTrace();
        } 
        try 
        {
            request.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        } 
        catch (UnsupportedEncodingException e1) 
        {
            Log.e(TAG, e1.toString());
            e1.printStackTrace();
        }

        if (consumer == null)
        {
            consumer = new CommonsHttpOAuthConsumer(OAuthConstants.TUMBR_CONSUMERKEY, OAuthConstants.TUMBR_SECRETKEY);
        }
        if (OAUTH_TOKEN == null || OAUTH_SECRET == null)
        {
            //throw new LoginErrorException(LoginErrorException.NOT_LOGGED_IN);
            Log.e(TAG, "Not logged in error");
        }
        consumer.setTokenWithSecret(OAUTH_TOKEN, OAUTH_SECRET);

            try 
            {
                consumer.sign(request);
            } 
            catch (OAuthMessageSignerException e) 
            {

            } 
            catch (OAuthExpectationFailedException e) 
            {

            } 
            catch (OAuthCommunicationException e) 
            {
            }

            HttpClient client = new DefaultHttpClient();

            //finally execute this request
            try 
            {
                HttpResponse response = client.execute(request, context);
                HttpEntity responseEntity = response.getEntity(); 
                if (responseEntity != null) 
                { 
                    Log.d(TAG, "responseEntety!=null");
                    try 
                    {
                        Log.d(TAG, EntityUtils.toString(responseEntity));
                    } 
                    catch (ParseException e) 
                    {
                        e.printStackTrace();
                        Log.e(TAG, e.toString());
                    } 
                    catch (IOException e) 
                    {
                        e.printStackTrace();
                        Log.e(TAG, e.toString());
                    } 
                }
                else
                {
                    Log.d(TAG, "responseEntety==null");
                }
            } 
            catch (ClientProtocolException e) 
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } 
            catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


    }

    else
    {
        Log.d(TAG, "upload imposble... Toklen not set");
    }
    PostToTumblr.this.finish();
}

现在,虽然有几件事情让我不满意(例如使用活动而不是服务),但这里的大问题显然是上传图片的问题。我绝不是第一个遇到这个问题的人,那么有没有人能够在Java中解决这个问题呢?

编辑1

尚未解决手头的问题,但创建了一个解决方法,可能对于遇到相同问题的人很有用。Tumblr提供通过邮件发布,您可以编程Android以后台发送电子邮件,如此处所示。这非常有效,但您需要要求用户提供其邮件帐户数据和Tumblr邮件地址才能发布。

编辑2

多年过去了,使用电子邮件已不再是简单易行的方式。有了jumblr,终于有了一个适用于Android的优秀Java API。OAuth认证并不好玩(它从来都不是),但一旦你克服了这个问题,它就很棒。
现在,技术上讲如何进行身份验证并不属于这里,但这是我的过长的问题,所以我将在此粘贴一些代码,如果您对此不感兴趣,请跳过它。
这使用了一个名为jumblr-0.0.10-jar-with-dependencies.jar的jar文件。
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;

import com.tumblr.jumblr.JumblrClient;
import com.tumblr.jumblr.request.RequestBuilder;
import com.tumblr.jumblr.types.Blog;
import com.tumblr.jumblr.types.User;

import org.scribe.builder.ServiceBuilder;
import org.scribe.builder.api.TumblrApi;
import org.scribe.model.Token;
import org.scribe.model.Verifier;
import org.scribe.oauth.OAuthService;

import java.io.File;


public class Tumblr
{
private static final String PROTECTED_RESOURCE_URL = "http://api.tumblr.com/v2/user/info";

static OAuthService service;
static Token requestToken=null;


public static void share(final Activity ctx, File file)
{
    Thread tt = new Thread(new Runnable()
    {
        @Override
        public void run()
        {
            JumblrClient client = new JumblrClient(Tumblr_Constants.CONSUMER_KEY, Tumblr_Constants.CONSUMER_SECRET);
            RequestBuilder requestBuilder = client.getRequestBuilder();
            requestBuilder.setConsumer(Tumblr_Constants.CONSUMER_KEY, Tumblr_Constants.CONSUMER_SECRET);
            SharedPreferences settings = ctx.getSharedPreferences("TumblrData", 0);
            String oauthToken=settings.getString("OauthToken", "");
            String oauthTokenSecret=settings.getString("OauthSecret", "");
            if(oauthToken.equals("") || oauthTokenSecret.equals(""))
            {
                authenticate(ctx);
                while(WebViewFragment.verifier.equals(""))
                {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                String v = WebViewFragment.verifier;
                Token accessToken = authenticatefurther(v);
                SharedPreferences.Editor edit = settings.edit();
                edit.putString("OauthToken", accessToken.getToken());
                edit.putString("OauthSecret", accessToken.getSecret());
                edit.commit();
                oauthToken=settings.getString("OauthToken", "");
                oauthTokenSecret=settings.getString("OauthSecret", "");
            }
            if(!oauthToken.equals("") && !oauthTokenSecret.equals(""))
            {
                client.setToken(oauthToken, oauthTokenSecret);

                User user = client.user();
                System.out.println(user.getName());

                for (Blog blog : user.getBlogs()) {
                    Log.d("TUMBLR", blog.getTitle());
                }
            }
        }

    });
    tt.start();

}

private static void authenticate(Context ctx) {
    service = new ServiceBuilder()
            .provider( TumblrApi.class )
            .apiKey(Tumblr_Constants.CONSUMER_KEY)
            .apiSecret(Tumblr_Constants.CONSUMER_SECRET)
            .callback("snapnao://snapnao.de/ok") // OOB forbidden. We need an url and the better is on the tumblr website !
            .build();


    Log.d("TUMBLR", "=== Tumblr's OAuth Workflow ===" );
    System.out.println();

    // Obtain the Request Token
    Log.d("TUMBLR", "Fetching the Request Token...");
    requestToken = service.getRequestToken();
    Log.d("TUMBLR", "Got the Request Token!");
    Log.d("TUMBLR", "");

    Log.d("TUMBLR", "Now go and authorize Scribe here:" );
    Log.d("TUMBLR", service.getAuthorizationUrl( requestToken ) );

    String url = service.getAuthorizationUrl(requestToken);


    Intent i = new Intent(ctx, WebViewFragment.class);
    i.putExtra("url", url);
    ctx.startActivity(i);


}

private static Token authenticatefurther(String v)
{
    Token accessToken = null;
    Log.d("TUMBLR", "And paste the verifier here");
    Log.d("TUMBLR", ">>");

    Verifier verifier = new Verifier( v);
    Log.d("TUMBLR", "");

    // Trade the Request Token and Verfier for the Access Token
    Log.d("TUMBLR", "Trading the Request Token for an Access Token...");
    accessToken = service.getAccessToken( requestToken ,
            verifier );
    Log.d("TUMBLR", "Got the Access Token!");
    Log.d("TUMBLR", "(if your curious it looks like this: " + accessToken + " )");

    Log.d("TUMBLR", "");

    return accessToken;
}


}

WebViewFragement看起来像这样:
import android.app.Activity;
import android.graphics.Bitmap;
import android.net.http.SslError;
import android.os.Bundle;
import android.util.Log;
import android.webkit.SslErrorHandler;
import android.webkit.WebView;
import android.webkit.WebViewClient;


public class WebViewFragment extends Activity 
{
public static String verifier="";
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.webviewfragment);

    String url = getIntent().getStringExtra("url");
    Log.d("TUMBLR", "webview-> "+url);
    WebView view = (WebView) findViewById(R.id.webView);
    view.setWebViewClient(
            new SSLTolerentWebViewClient()
    );
    view.getSettings().setJavaScriptEnabled(true);
    view.loadUrl(url);
}

// SSL Error Tolerant Web View Client
private class SSLTolerentWebViewClient extends WebViewClient {

    @Override
    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
        handler.proceed(); // Ignore SSL certificate errors
    }

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
        Log.d("TUMBLR", "+++++"+url);
        if(url.contains("oauth_verifier="))
        {
            String[] x = url.split("oauth_verifier=");
            verifier=x[1].replace("#_=_", "");
            WebViewFragment.this.finish();
        }
    }
}
}

为什么您没有像“type”和“caption”一样在名称-值对中编码“data”输入名称? - Madbreaks
实际上,对输入名称进行编码并不是必要的(正如在帖子开头的文本帖子的工作代码中所看到的那样)。这只是我尝试让它工作的其中一件事。为了清晰起见,应该再次将其删除以示例代码。 - Lukas Ruge
1
我注意到的第一件事是你使用了 data 而不是 source,但你发送的是一个字符串而不是一个数组。如果你只上传一张照片,请尝试使用编码字符串的 source 或一个带有一个编码字符串元素的数组作为 data - Ally
2
有人成功上传了一个jpg图像。请尝试使用Bitmap.CompressFormat.JPEG。 - Omar
@Ally 'source' 用于图片的 URL,'data' 用于发送实际的图片字节。具体信息在这里:http://www.tumblr.com/docs/en/api/v2#posting - Jabari
如果有人有解决方案,请回答我的问题。http://stackoverflow.com/questions/21739014/upload-image-from-sd-card-on-tumbler-in-android - Akanksha Rathore
5个回答

3
您可以使用 jumblr - Tumblr 的 Java 客户端轻松完成此操作。
JumblrClient client = new JumblrClient(Constant.CONSUMER_KEY,Constant.CONSUMER_SECRET);

client.setToken(preferences.getString("token",null), preferences.getString("token_secret", null));

PhotoPost pp = client.newPost(client.user().getBlogs().get(0).getName(),PhotoPost.class);

pp.setCaption(caption);
// pp.setLinkUrl(link);
// pp.setSource(mImage); // String URL
pp.setPhoto(new Photo(imgFile));
pp.save();

1
谢谢,eltabo在另一个答案中提到了这一点。当我遇到这个问题时,jumblr还不存在,现在它是最好的解决方案。 - Lukas Ruge

3

为什么不使用Jumblr,它是Tumblr的官方Java客户端。

祝好。


1
从提交历史记录中我得知,在我发布问题时它并不存在。现在看起来值得一试。谢谢。 - Lukas Ruge
哎呀,也许我以为你有通量电容器 :D - eltabo
我尝试了Jumblr,但无法上传图片... https://stackoverflow.com/questions/26271523/jumblr-post-photo-on-android - mythicalprogrammer

0

这对我起作用了...

nameValuePairs.add(new BasicNameValuePair(URLEncoder
                .encode("type", "UTF-8"),
                     URLEncoder.encode("photo", "UTF-8")));
Log.e("Tumblr", "Image shareing file path" + filePath);
nameValuePairs.add(new BasicNameValuePair("caption", caption));
nameValuePairs.add(new BasicNameValuePair("source", filePath));`

其中filePath是http网址。


谢谢你的回答。我已经提交了一个编辑来整理格式 - 当提问或回答问题时,如果你使用四个空格缩进代码而不是使用重音符号,它们会更整洁,因为它们不会保留你的换行符。 - nurdglaw
我得到了以下内容: {"meta":{"status":400,"msg":"错误请求"},"response":{"errors":["上传照片出错。"]}} - Akanksha Rathore

0

我使用了multipart

公共类VideoUploader扩展了AsyncTask {

    ProgressDialog progressDialog;

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        progressDialog = ProgressDialog.show(RecordingActivity.this, "",
                "Uploading video.. ");
        super.onPreExecute();
    }

    @Override
    protected JSONObject doInBackground(String... params) {
        JSONObject jsonObject = null;
        StringBuilder builder = new StringBuilder();
        try {
            String url = UrlConst.VIDEO_URL;
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(url);

            FileBody filebodyVideo = new FileBody(new File(params[0]));
            StringBody title = new StringBody("uploadedfile: " + params[0]);
            StringBody description = new StringBody(
                    "This is a video of the agent");
            // StringBody code = new StringBody(realtorCodeStr);

            MultipartEntity reqEntity = new MultipartEntity();
            reqEntity.addPart("uploadedfile", filebodyVideo);
            reqEntity.addPart("title", title);
            reqEntity.addPart("description", description);
            // reqEntity.adddPart("code", code);
            httppost.setEntity(reqEntity);

            // DEBUG
            System.out.println("executing request "
                    + httppost.getRequestLine());
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity resEntity = response.getEntity();

            // DEBUG
            StatusLine status = response.getStatusLine();
            int statusCode = status.getStatusCode();
            System.out.println(response.getStatusLine());
            if (resEntity != null) {
                System.out.println(EntityUtils.toString(resEntity));
            } // end if

            if (resEntity != null) {
                resEntity.consumeContent();
            } // end if
            if (statusCode == 200) {
                InputStream content = resEntity.getContent();
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(content));
                String line;
                while ((line = reader.readLine()) != null) {
                    builder.append(line);
                }
                jsonObject = new JSONObject(builder.toString());
                return jsonObject;
            } else {
                Log.e(LoginActivity.class.toString(),
                        "Failed to download file");
            }
            httpclient.getConnectionManager().shutdown();

        } catch (Exception e) {
            // TODO: handle exception
        }
        return null;
    }

    @Override
    protected void onPostExecute(JSONObject result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        progressDialog.dismiss();
        if (result != null) {

            try {

                JSONObject jsonObject = result
                        .getJSONObject(ParsingTagConst.COMMANDRESULT);
                String strSuccess = jsonObject
                        .getString(ParsingTagConst.SUCCESS);
                String responseString = jsonObject
                        .getString(ParsingTagConst.RESPONSE_STRING);
                Toast.makeText(RecordingActivity.this, "" + responseString,
                        Toast.LENGTH_LONG).show();
                if (strSuccess.equals("1")) {
                    // get here your response
                }

            } catch (Exception e) {
                // TODO: handle exception
            }
        }

    }

}



enter code here

0
我使用以下方法完成了。你可以试试看。
// paramString =“你想放在标题中的文本”
private void postPhotoTumblr(String uploadedImagePhotoUrl, String paramString)
{
  CommonsHttpOAuthConsumer localCommonsHttpOAuthConsumer = getTumblrConsumer();
  String str1 = "logged in username";
  String encodedImage = uploadedImagePhotoUrl;
  DefaultHttpClient localDefaultHttpClient = new DefaultHttpClient();
  HttpPost localHttpPost = new HttpPost("http://api.tumblr.com/v2/blog/" + str1 + ".tumblr.com/post");
  try
  {

    ArrayList localArrayList = new ArrayList();
    localArrayList.add(new BasicNameValuePair("type", "photo"));
    BasicNameValuePair localBasicNameValuePair = new BasicNameValuePair("caption", paramString);
    localArrayList.add(localBasicNameValuePair);
    localArrayList.add(new BasicNameValuePair("data",encodedImage));
    UrlEncodedFormEntity localUrlEncodedFormEntity = new UrlEncodedFormEntity(localArrayList);
    localHttpPost.setEntity(localUrlEncodedFormEntity);
    localCommonsHttpOAuthConsumer.sign(localHttpPost);
    InputStream localInputStream = localDefaultHttpClient.execute(localHttpPost).getEntity().getContent();
    InputStreamReader localInputStreamReader = new InputStreamReader(localInputStream);
    BufferedReader localBufferedReader = new BufferedReader(localInputStreamReader);
    StringBuilder localStringBuilder = new StringBuilder();
    while (true)
    {
      String str2 = localBufferedReader.readLine();
      if (str2 == null)
      {
        Log.i("DATA post resp", localStringBuilder.toString());
        break;
      }
      localStringBuilder.append(str2);
    }
  }
  catch (ClientProtocolException localClientProtocolException)
  {
    localClientProtocolException.printStackTrace();
  }
  catch (IOException localIOException)
  {
    localIOException.printStackTrace();
  }
  catch (OAuthMessageSignerException localOAuthMessageSignerException)
  {
    localOAuthMessageSignerException.printStackTrace();
  }
  catch (OAuthExpectationFailedException localOAuthExpectationFailedException)
  {
    localOAuthExpectationFailedException.printStackTrace();
  }
  catch (OAuthCommunicationException localOAuthCommunicationException)
  {
    localOAuthCommunicationException.printStackTrace();
  }
}

编辑:首先将图像上传到Web服务器,然后获取URL并尝试使用上传的URL或文件路径进行发布。这样肯定会正常工作... :)

我得到了{"meta":{"status":400,"msg":"Bad Request"},"response":{"errors":["Error uploading photo."]}} - Akanksha Rathore
我能够发布文本消息,而不是图片。你能帮我吗? - Akanksha Rathore

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接