gpt4 book ai didi

android - 使用 Twitter4j 从 Android 上传图片到 Twitter

转载 作者:行者123 更新时间:2023-11-29 14:16:06 24 4
gpt4 key购买 nike

有没有办法调用Twitter API *update_with_media* POST 方法使用Twitter4j 上传照片?我的意思是,不使用像 TwitPic 或 YFrog 这样的中间服务?

如果不可能,那么使用来自 Android 原生应用的图片发布推文的最佳方式是什么?谁能告诉我一个适用于 Android 应用程序的工作示例?

谢谢!!

最佳答案

if (requestCode == CAMERA_REQUEST) {
mImageUri = data.getData();
mPath = getRealPathFromURI(mImageUri); //from Gallery

if (mPath == null)
mPath = mImageUri.getPath(); //from File Manager

if (mPath != null)
bitmap = BitmapFactory.decodeFile(mPath);
} else {
mPath = mImageUri.getPath();
bitmap = BitmapFactory.decodeFile(mPath);
}
Authorization auth=twitter.getAuthorization();
ImageUpload uploadPhoto=ImageUpload.getTwitpicUploader(TwitPic_api_Key, (OAuthAuthorization) auth);
Log.d(TAG, "Start sending image...");

try {
url = uploadPhoto.upload(new File(mPath));
result = 1;
Log.d(TAG, "Image uploaded, Twitpic url is " + url);
} catch (Exception e) {
Log.e(TAG, "Failed to send image");

e.printStackTrace();
}

关于android - 使用 Twitter4j 从 Android 上传图片到 Twitter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10931136/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com