gpt4 book ai didi

android - Twitpic 错误 - 无效的用户名和密码

转载 作者:太空宇宙 更新时间:2023-11-03 11:19:32 25 4
gpt4 key购买 nike

我正在使用 twitpic 库在 Twitter 上发布图片,但我收到了无效的 twitpic 用户名和密码错误。这个有解决办法吗??witpic的用户名和密码是什么。我只是使用我的 Twitter ID 和密码代替它。

这是我的代码

// Create file
File picture = new File(Environment.getExternalStorageDirectory()+"/image.jpg");
if(picture.exists())
{
System.out.println("Picture accesseds");
}

// Create TwitPic object and allocate TwitPicResponse object
TwitPic tpRequest = new TwitPic("gauravarora90", "gaurav");
TwitPicResponse tpResponse = null;

// Make request and handle exceptions
try {
tpResponse = tpRequest.uploadAndPost(picture, "Hello World!!!");
} catch (IOException e) {
e.printStackTrace();
} catch (TwitPicException e) {
e.printStackTrace();
}


// If we got a response back, print out response variables
if(tpResponse != null) {
tpResponse.dumpVars();
System.out.println(tpResponse.getStatus());
if(tpResponse.getStatus().equals("ok")){
Toast.makeText(getApplicationContext(), "Photo posted on Twitter.",Toast.LENGTH_SHORT).show();
//picture.delete();
}
}

请帮助我。提前致谢。

最佳答案

试试这段代码:

ConfigurationBuilder cb = new ConfigurationBuilder();

cb.setOAuthConsumerKey(TwitterClass.CONSUMER_KEY);
cb.setOAuthConsumerSecret(TwitterClass.CONSUMER_SECRET);
cb.setOAuthAccessToken(tw.getAccessToken());
AccessToken a = new AccessToken(tw.getAccessToken(),tw.getSecretToken());


TwitterFactory tf = new TwitterFactory(cb.build());
t4jTwitter = tf.getInstance();

t4jTwitter.setOAuthAccessToken(a);

Configuration conf = new ConfigurationBuilder()
.setOAuthConsumerKey(TwitterClass.CONSUMER_KEY)
.setOAuthConsumerSecret(TwitterClass.CONSUMER_SECRET)
.setOAuthAccessToken(tw.getAccessToken())
.setOAuthAccessTokenSecret(tw.getSecretToken())
.build();

OAuthAuthorization auth = new OAuthAuthorization (conf, conf.getOAuthConsumerKey (), conf.getOAuthConsumerSecret (),
new AccessToken (conf.getOAuthAccessToken (), conf.getOAuthAccessTokenSecret ()));

ImageUpload upload = ImageUpload.getTwitpicUploader (TWITPIC_KEY, auth);

try {
// String url = upload.upload(new File("/mnt/sdcard/download/3029302084159350163.jpg"));


//result = 1;


URL myfileUrl=new URL(strFilePath);

HttpURLConnection conn = (HttpURLConnection) myfileUrl
.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();


// String url = upload.upload(new File("/mnt/sdcard/download/3029302084159350163.jpg"), StaticData.strTwitte);


String url = upload.upload(StaticData.strTwitte, is);

System.out.println("Image url"+url);
System.out.println("Image uploaded");
result_img=1;
twitter4j.Status status = t4jTwitter.updateStatus(StaticData.strTwitte+"\n"+url);
int statusId = (int)status.getId();

//Log.d(TAG, "Image uploaded, Twitpic url is " + url);
} catch (Exception e) {
//Log.e(TAG, "Failed to send image");
result_img=0;
System.out.println("Failed to send image");
e.printStackTrace();
}

关于android - Twitpic 错误 - 无效的用户名和密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10885879/

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