Twitpic Error - invalid username and password

I use the twitpic library to post the image on twitter, but I get an invalid username and password for twitpic. Is there any solution for this? What is witpic username and password. I just use my Twitter id and password instead.

Here is my code

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

Please help me. Thanks in advance.

+4
source share
1 answer

try this code:

 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(); } 
0
source

Source: https://habr.com/ru/post/1416016/


All Articles