Twitter exception4 04:The URI requested is invalid - android

I want to send direct message to user's followers using my android application.I have tried following code
String access_token = mSharedPreferences.getString(
Constants.PREF_KEY_OAUTH_TOKEN, "");
// Access Token Secret
String access_token_secret = mSharedPreferences.getString(
Constants.PREF_KEY_OAUTH_SECRET, "");
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setDebugEnabled(true);
builder.setOAuthConsumerKey(Constants.TWITTER_CONSUMER_KEY);
builder.setOAuthConsumerSecret(Constants.TWITTER_CONSUMER_SECRET);
builder.setOAuthAccessToken(access_token);
builder.setOAuthAccessTokenSecret(access_token_secret);
TwitterFactory tf = new TwitterFactory(builder.build());
Twitter twitter = tf.getInstance();
DirectMessage message = null;
try {
message = twitter.sendDirectMessage(
frndsDetails.get(position).getId(), "Hi");
System.out.println("Sent: " + message.getText()
+ " to #" + message.getRecipientScreenName());
} catch (TwitterException e) {
// TODO Auto-generated catch block
Log.e("Twitter exception", "" + e.getMessage());
e.printStackTrace();
}
But got following exception
02-26 13:48:16.287: E/Twitter exception(707): 404:The URI requested
is invalid or the resource requested, such as a user, does not exists.
Also returned when the requested format is not supported by the
requested method. 02-26 13:48:16.287: E/Twitter exception(707):
message - Sorry, that page does not exist 02-26 13:48:16.287:
E/Twitter exception(707): code - 34 02-26 13:48:16.397:
W/System.err(707): at android.view.View.performClick(View.java:3511)
Is there any other method for sending direct message.Please help me. Thanks in advance.

I have used following code in my application for sending direct messages to the followers. May be this can helpful to you.
StringBuilder builder = new StringBuilder();
builder.append("#").append(twitterFriendObj.screenName).append(" ");
Status status = twitter.updateStatus(builder+"Hi this is test message");
Here we need to send follower screen name to send direct message.

Related

posting status to twitter using twitter4j in android

im trying to post status updates to twitter. I am using the Twitter4j lib. My code runs without crashing but in the log cat is says "401:Authentication credentials
(https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync.
{"request":"\/1.1\/statuses\/update.json","error":"Read-only application cannot POST."}
any help? I have signed up on twitter and i check the read and write permissions.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Runnable runnable = new Runnable() {
public void run() {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey("kkwfh72794883jjg");
builder.setOAuthConsumerSecret("77j3jgweqwewerrud3434567hgfd");
// Access Token
String access_token = "lokiujyhtgrfedvwn325zckjdhdgeAHGsw23";
// Access Token Secret
String access_token_secret = "QsRgfgHJMsjeh5762JHF2dgswrfMNQljsG";
AccessToken accessToken = new AccessToken(access_token, access_token_secret);
Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken);
// Update status
try {
twitter4j.Status response = twitter.updateStatus("updated via myapp");
Log.d("Status", "> " + response.getText());
// Error in updating status
} catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.d("Twitter Update Error", e.getMessage());
}
}
};
Thread mythread = new Thread(runnable);
mythread.start();
}
I was having similar issue. What I did was:
Check if your app has Read and Write permissions
If it doesn't, check the permissions radiobutton, and click Update Settings
After that, you must manually regenerate your access tokens (I regenerated consumer key, too)
Hope this will help other strugglers.
I think you should change your code:
Like this:
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey("kkwfh72794883jjg");
builder.setOAuthConsumerSecret("77j3jgweqwewerrud3434567hgfd");
OAuthAuthorization auth = new OAuthAuthorization(builder.build());
// Access Token
String access_token = "lokiujyhtgrfedvwn325zckjdhdgeAHGsw23";
// Access Token Secret
String access_token_secret = "QsRgfgHJMsjeh5762JHF2dgswrfMNQljsG";
Twitter twitter = new TwitterFactory().getInstance(auth);

Upload audio url in twitter android

i am stuck in Twitter integration.I am done with image uploading through url but i am not able to upload audio or video url to twitter.
Any help is appreciated. Thanx guys
Twitter Code for uploading youtube url:
twitter.updateStatus("This is My Youtube url Test http://youtu.be/pfHxl46KyZM");
Logcat:
403:The request is understood, but it has been refused. An accompanying error message will explain why. This code is used when requests are being denied due to update limits (https://support.twitter.com/articles/15364-about-twitter-limits-update-api-dm-and-following).
message - Error creating status.
code - 189
Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=b2b52c28 or
http://www.google.co.jp/search?q=12c480e1
TwitterException{exceptionCode=[b2b52c28-12c480e1], statusCode=403, message=Error creating status., code=189, retryAfter=-1, rateLimitStatus=null, version=3.0.6-SNAPSHOT}
String tweetUrl = "https://twitter.com/intent/tweet?text=Put your Audio URL here &url="
+ "https://www.google.com&hashtags=android,twitter";
Uri uri = Uri.parse(tweetUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
OR
// Consumer
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
// Access Token
AccessToken accessToken = null;
accessToken = new AccessToken(ACCESS_TOKEN, ACCESS_SECRET);
twitter.setOAuthAccessToken(accessToken);
// Posting Status
Status status = null;
try {
status = twitter.updateStatus("YOUR_AUDIO_LINK");
} catch (TwitterException e) {
e.printStackTrace();
}
System.out.println("Successfully updated the URL: "
+ status.getText());
You cannot upload video directly to Twitter - they simply don't support it.
Follow these steps.
1.Upload the video to a 3rd party service (like YouTube)
2.Get the public URL of the uploaded video
3.Add the URL to the status you send to Twitter - e.g. "Look at my Birtday video http://youtube.com/id"
If you want, you can add a thumbnail of the video as an image attachment
Hope this is what you are looking for.
Note sure but check if this helps you:-
String videoPath="video file path";
TwitterSession twitterSession = new TwitterSession(MainActivity.this);
AccessToken accessToken = twitterSession.getAccessToken();
Values values = new Values();
values.setSession(new Session());
TwitvidApi api = new TwitvidApi(values);
api.setSecureUrlEnabled(false);
Session session;
try {
session = api.authenticate(new TwitterAuthPack.Builder()
.setConsumerKey(twitter_consumer_key)
.setConsumerSecret(twitter_secret_key)
.setOAuthToken(accessToken.getToken())
.setOAuthTokenSecret(accessToken.getTokenSecret()).build());
api.getValues().setSession(session);
final UploadHelper helper = new UploadHelper(api);
File file = new File(videoPath);
TwitvidPost twitvidPost = new TwitvidPost.Builder().setFile(file)
.setChunkSize(10485760).setMessage("Twitvid test")
.setPostToTwitter(true).create();
try {
if (helper.upload(twitvidPost)) {
Toast.makeText(MainActivity.this, "Posted on Twitter and Twitvid" ,Toast.LENGTH_LONG).show();
Log.d("MainActivity", "Posted on Twitter and Twitvid");
} else {
Toast.makeText(MainActivity.this, "Post failed", Toast.LENGTH_LONG)
.show();
Log.d("MainActivity", "Posted failed");
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (ApiException e1) {
e1.printStackTrace();
}

Posting data from android app on my Twitter's account as tweet

I'm trying to post my data through android app on my twitter account so how should i do it.
i have tried a way, below is the code, and in that it is showing the data on my account and i need to click on the tweet button to get it tweeted. So can i know how to post it directly without asking me to tweet. Like Four Square app
public void open(View view){
String text = "Share Your Experiance ....!!!";
String url = "twitter://post?message=";
try {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url + Uri.encode(text)));
startActivity(i);
} catch (android.content.ActivityNotFoundException e) {
Toast.makeText(this, "Can't send tweet! Please install twitter...", 2).show();
}
Thanks in Advance !!!
Firstly you have to check are you logged with twitter or not after as your condition you can apply this snippet code.
I think you follow the all basics for twitter integration in your code.
public void uploadPic(String message, String getImgUrl)
throws Exception {
try {
System.out.println(" ON UPLOAD PIC FUNCTION getImgUrl "+getImgUrl);
// URL url = new URL("http://faveplatewebservice.siplstudio.com/uploads/big_dish/oooo14n7464rO4_thumb.png");
URL url = new URL(getImgUrl);
URLConnection urlConnection = url.openConnection();
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
StatusUpdate status = new StatusUpdate("Check Out FavPlates on appstore, which offers you to add and find exciting dishes near you. "+message);
//status.setMedia(file);
status.setMedia("Check Out FavPlates on appstore, which offers you to add and find exciting dishes near you. "+message, in);
mTwitter.updateStatus(status);
} catch (TwitterException e) {
Log.d("TAG", "Pic Upload error" + e.getExceptionCode());
throw e;
}
}
hope it will help you!!
If you stuck anywhere then inform me.
Thankss!!

gData: get account(self contact) first and last name

I want to get first and last name of a google account using gdata library. I have the auth token(I take it from android device - send it to my java servlet- then should add an insert into a mysql db with first, last, display name and provider_uid(provider_uid is the form of https://www.google.com/accounts/o8/id?id=AItOawmyn...)).
I used Contacts feed like this(without success):
public String tryGoogleAuthentication(String auth_token){
ContactsService contactsService = new ContactsService("...");
contactsService.setUserToken(auth_token);
//contactsService.setAuthSubToken(auth_token);
ContactFeed feed = null;
try {
feed = contactsService.getFeed(new URL("https://www.google.com/m8/feeds/contacts/" + "someEmail#gmail.com" + "/full?max-results=10000"), ContactFeed.class);
} catch (IOException e) {
e.printStackTrace();
return CONST.GOOGLE_AUTH_INVALID_TOKEN;
} catch (ServiceException e) {
e.printStackTrace();
return CONST.GOOGLE_AUTH_INVALID_TOKEN;
} catch (NullPointerException e) {
e.printStackTrace();
return CONST.GOOGLE_AUTH_INVALID_TOKEN;
}
if (feed == null)
return "";
String externalId = feed.getId();
Person person = feed.getAuthors().get(0);
String email = person.getEmail();
String name = person.getName();
String nameLang = person.getNameLang();
String extensionLocalName = person.getExtensionLocalName();
String uri = person.getUri();
System.out.println("externalId: " + externalId);
System.out.println("email: " + email);
System.out.println("name: " + name);
System.out.println("nameLang: " + nameLang);
System.out.println("extension local name: " + extensionLocalName);
System.out.println("URI: " + uri);
System.out.println(feed.getSelf().getEntries().get(0).getTitle().getPlainText());
return CONST.STATUS_OK;
}
Also,
System.out.println("ID: " + feed.getSelf().getEntries().get(0).getId());
will output:
ID: http://www.google.com/m8/feeds/contacts/someEmail%40gmail.com/base/c....
but I want something like this:
https://www.google.com/accounts/o8/id?id=AItOawmyn...
I need this to insert into an existing data base.
Please note that I want the info only for the account, not for it's contacts.
Thanks,
Alex
Please see this answer from google groups for resolution. The problem is that I cannot access user profile with the auth_token taken from the android because it's a Client Login token, and Client Login does not have a scope for accessing user's profile. I integrated OAUTH login in android like this and with the token returned, I can access user's profile.
Alex.

When access to directmessage in twitter4j, an error shows "unable to parse '3577866941' as integer"

I have set the value of ACCESS_TOKEN,ACCESSTOKEN_SECRET,CONSUMER_KEY,CONSUMER_SECRET which I got from dev.twitter but it crashes when the application runs.I use twitter4j-core-2.1.8-SNAPSHOT.jar as library.The code is given bellow.
public ResponseList<DirectMessage> dmList=null;
public static AccessToken token = new AccessToken(ACCESS_TOKEN, ACCESSTOKEN_SECRET);
TwitterFactory factory = new TwitterFactory();
twitter = factory.getInstance();
twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
twitter.setOAuthAccessToken(token);
try {
dmList = twitter.getDirectMessages(new Paging(1,15));
} catch (TwitterException e) {
e.printStackTrace();
}
Thanks.
Twitter userID and tweetID are not 32 bit integers. They recently upgraded them to 64bit, maybe your library is out of date ?

Categories

Resources