I have recently noticed that I keep getting a 403 error while doing twitter search. My application was working until couple of days back when i noticed the error.
I checked with Twitter & they say my IP is not blocked, I am also within the rate limit = about 60 search requests/per hour.
Here's how i was initializing the Twitter object -
private static Twitter TWITTER_CLIENT = new TwitterFactory().getInstance();
After i noticed the error, i tried the following & still no success -
private static Twitter TWITTER_CLIENT = new TwitterFactory().getInstance("user", "password");
Here's how i am searching -
TWITTER_CLIENT.search(new Query("#keyword1 OR #keyword2"));
I tried this URL (curl http://search.twitter.com/search.json?q=ipad) from my server & it works alright.
Following is the exception. I am on java6 + Twitter4j v2.1.2. Would really appreciate any help. Thanks.
TwitterException{statusCode=403, retryAfter=0, rateLimitStatus=null}
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:301)
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:68)
at twitter4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:82)
at twitter4j.Twitter.search(Twitter.java:193)
Most likely the reason is basic auth shutdown by Twitter (aka OAuthcalypse):
Basic Auth Shutdown
You need to switch to using OAuth.
Recently i got the same error while executing similar code.
To fix it, please go to
https://apps.twitter.com/app/your_app_id
Click on Keys and access token
In Access Level, click modify app permission and choose the 3rd option: Read, Write and Access direct messages
Click on update. ( Note: you might have to add your mobile no and verify with otp to get this access if you dont have your no added in twitter)
Regenerate both Consumer key & secretand Access token & secret using the clickable button
Us e the new keys in your program
And you are done! Your program will start working.
Related
I'm building a web portal by using Java; besides other requirements, I'm struggling my mind one one very simple (at least at first view) requirement:
my customer wants on his portal the first N posts of his facebook wall
and he wants to read the first N tweets of his twitter page
Since my java code is based on Spring, I wanted to use spring social, spring social twitter and spring social facebook in order to satisfy the requirement
With twitter I had no problem; in fact I
created an app on twitter
got twitter app id and app secret
prepared code
In a couple of hours, all worked pretty good
Problems were born with facebook and it's a lot of time I'm fighting with it
I passed from spring social to facebook4j (since this last one seems to me stronger).
I did the following
created an app on FB
got the facebook appId and appSecret
told to the code that I need the read_stream permission
prepared the code
But I'm not able in reading posts from my wall
Is there anyone who was able in satisfying this kind of scenario?
here my facebook4j code
private static final Logger log = LoggerFactory.getLogger(FacebookTest.class.getName());
public static void main (String[] a)
{
try
{
ConfigurationBuilder cfgBui = new ConfigurationBuilder();
cfgBui.setDebugEnabled(true);
cfgBui.setOAuthAppId(myAppId);
cfgBui.setOAuthAppSecret(myAppSecret);
cfgBui.setUseSSL(true);
Configuration cfg = cfgBui.build();
FacebookFactory ff = new FacebookFactory(cfg);
OAuthSupport support = new OAuthAuthorization(cfg);
support.setOAuthPermissions("read_stream");
AccessToken appAccessToken = support.getOAuthAppAccessToken();
Facebook face = ff.getInstance(appAccessToken );
ResponseList<Post> posts = face.searchPosts("test");
for (Post post : posts)
{
System.out.println(post.getId());
}
} catch (Exception e)
{
log.error("Errore", e);
}
}
As far as I understood, I should need the user access token, but I don't know how to generate it; should I create a login flow and show to the user the FB login dialog? If so, why should I create app id and app secret? They have no sense in my scenario
Moreover...in my case...the server side should authenticate on FB and read posts from a well know user wall (the wall of my customer...) so....where should I present the login dialog? where should I redirect after the FB login?
Is there any good man :) who can clarify to me the FB read post flow?
You MUST use one of the possibilities to authorize the user (with read_stream) in order to get access to his stream. Here´s the link to all the possibilities: https://developers.facebook.com/docs/facebook-login/v2.2
You can also generate Access Tokens with the Graph API Explorer: https://developers.facebook.com/tools/explorer/
Detailed information about Access Tokens and how to generate them can be found in the following links:
https://developers.facebook.com/docs/facebook-login/access-tokens
http://www.devils-heaven.com/facebook-access-tokens/
Keep in mind that an Extended User Token only lasts for 60 days, after that your customer would have to refresh it manually. In general, you are not allowed to use User Profiles for commercial reasons, and it´s very unusual to show a User stream on a website.
Better: Use a Facebook Page. /page-id/feed with an Extended Page Token that lasts forever.
If you use spring-social-facebook, you could let the user login via (front-end login flow) and then you can access the users wall. However, user would need to login and authorize your app to perform the operations.
Here is a spring social sample project that demo's how spring-social-facebook login is done https://github.com/spring-projects/spring-social-samples
Also, within your java code you can use feedoperations to gather information about home feed and also query against it. Checkout the documentation.
facebook.feedOperations().
This question already has answers here:
How to call API (Oauth 1.0)?
(4 answers)
Closed 5 years ago.
I wrote the code to reconnect the Intuit. My code is:
client.reConnect(INTUIT_QB_OAUTH_CONSUMER_KEY,INTUIT_QB_OAUTH_CONSUMER_SECRET,
"accessTOken","accessTokenKeySecret");
I can't be sure about it is working or not. What is the best way to test it? I went through think page of intuit: https://appcenter.intuit.com/Playground/OAuth/IA/
but I don't have so much idea regarding to it.
Another Main issue i am facing it that, How to get new token again?? As defined by intuit checklist, We should not call OauthFlow again.
....................................................................................................................
Added part of question:
I know that, Playground helping me lot.
But I am searching a mechanism to get new accessToken and accessTokenSecret after I call reconnect api. I am calling api as follows:
IAPlatformClient client = new IAPlatformClient();
client.reConnect(INTUIT_QB_OAUTH_CONSUMER_KEY,INTUIT_QB_OAUTH_CONSUMER_SECRET,
"accessTOken","accessTokenKeySecret");
This is working fine, because if i try to use old tokens from database it throws exception as defined by Intuit.
And This code i have to run using scheduler mechanism. After calling reconnect api, I have to update my existing keys on database But I can't get those newly generated keys. So, Please suggest me the mechanism which returns new accessToken and accessTokenSecret.
I have tried this:
Map<String, String> requesttokenmap=client.getRequestTokenAndSecret(INTUIT_QB_OAUTH_CONSUMER_KEY,INTUIT_QB_OAUTH_CONSUMER_SECRET);
then,
final Map<String, String> oauthAccessTokenMap =
client.getOAuthAccessToken(verifierCode, requesttokenmap.get(IntuitSSOConstants.REQUEST_TOKEN),
requesttokenmap.get(IntuitSSOConstants.REQUEST_TOKEN_SECRET),
PropsUtil.get(CommonConstants.INTUIT_QB_OAUTH_CONSUMER_KEY),
PropsUtil.get(CommonConstants.INTUIT_QB_OAUTH_CONSUMER_SECRET));
But I will not have verifierCode code, which have to pass as a parameter in last block of code.
So, how can I get accessToken and accessTokenSecret?
Please refer this SO thread.
QuickBook Online Reconnect & expire Issue
For your first Qts, Please check - https://developer.intuit.com/docs/0025_quickbooksapi/0053_auth_auth/oauth_management_api
Please find below steps to get OAuth tokens using which you can make API call against your QBO account.
If you create an app in appcenter, you'll get consumerKey and consumerSecret.
https://developer.intuit.com/Application/Create/IA
Using the above two tokens, you can generate accessToken and accessSecret from the OAuthPlayground.
https://appcenter.intuit.com/Playground/OAuth/IA
PN - After completing C2QB(OAuth) flow, you should use 'App Menu API Test.' option which will show you accessToken and accessSecret.
All the above steps are mentioned in this - https://developer.intuit.com/docs/0025_quickbooksapi/0055_devkits/0150_ipp_.net_devkit_3.0/0002_synchronous_calls/0001_data_service_apis
Thanks
I am completely new to this site. I was searching for an answer for my problem. But I saw the same problem asked by someone in this website. The question is here
I am using windows 7. I didn't not get answer there in that link..so I am asking the same question again. I want to open a gmail account link in a browser from a java application. Yes I do know about browse() method in Desktop class. The thing is that I can open the gmail website but I need to open directly the specified gmail account while username and password are provided. Any ideas?
Okay, so take this with a couple of caveats: 1. the last time I played with Google APIs was in an older version, so this may be quite different now, 2. this code isn't tested, I'm just writing it up partially from memory and partially from an old project of mine. Think of it more like pseudo-code, and 3. if this does by chance work, this is a pretty dirty solution. Hopefully this can set you on the track of finding a better way to do this with the API.
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey( [insert consumer key here] );
oauthParameters.setOAuthConsumerSecret( [insert consumer secret here] );
OAuthSigner signer = new OAuthHmacSha1Signer();
GoogleOAuthHelper oauthHelper = new GoogleOAuthHelper(signer);
oauthParameters.setScope("https://mail.google.com/mail"); //no clue if this is a valid scope or not
oauthHelper.getUnauthorizedRequestToken(oauthParameters);
String requestUrl = oauthHelper.createUserAuthorizationUrl(oauthParameters);
Desktop desktop = Desktop.getDesktop();
URI url;
url = new URI(requestUrl);
//this will make the user log in to authorize your app
desktop.browse(url);
//auth token response from Google, you can use this to authenticate your app if there are other requests you want to make against the user account
String token = oauthHelper.getAccessToken(oauthParameters);
//since you made sure the user is logged into their account to authorize your app, their gmail can now just be opened. Yes, very dirty. I know. (if it all works)
desktop.browse("https://www.gmail.com/");
I am trying to get the Connections or user's friends info from LinkedIn using LinkedIn jar for android and example given in google code, but i wont get Connections using linkedInApiClient.getConnectionsForCurrentUser() this method call it returns null, but i can access user current profile info using linkedInApiClient.getProfileForCurrentUser()
can any body suggest me how to get User connections information in linkedIn in android. Or guide me the the wright way.
I got the solution for the above ask question, what I was doing wrong, was that we have to pass an argument of the ProfileField information we want, like this:
final Set<ProfileField> connectionFields = EnumSet.of(ProfileField.ID, ProfileField.MAIN_ADDRESS,
ProfileField.PHONE_NUMBERS, ProfileField.LOCATION,
ProfileField.LOCATION_COUNTRY, ProfileField.LOCATION_NAME,
ProfileField.FIRST_NAME, ProfileField.LAST_NAME, ProfileField.HEADLINE,
ProfileField.INDUSTRY, ProfileField.CURRENT_STATUS,
ProfileField.CURRENT_STATUS_TIMESTAMP, ProfileField.API_STANDARD_PROFILE_REQUEST,
ProfileField.EDUCATIONS, ProfileField.PUBLIC_PROFILE_URL, ProfileField.POSITIONS,
ProfileField.LOCATION, ProfileField.PICTURE_URL);
Connections connections = client.getConnectionsForCurrentUser(connectionFields);
Im working on oauth 1 Sparklr and Tonr sample apps and I'm trying to create a two-legged call. Hipoteticly the only thing you're supposed to do is change the Consumer Details Service from (Im ommiting the igoogle consumer info to simplify):
<oauth:consumer-details-service id="consumerDetails">
<oauth:consumer name="Tonr.com" key="tonr-consumer-key" secret="SHHHHH!!!!!!!!!!"
resourceName="Your Photos" resourceDescription="Your photos that you have uploaded to sparklr.com."/>
</oauth:consumer-details-service>
to:
<oauth:consumer-details-service id="consumerDetails">
<oauth:consumer name="Tonr.com" key="tonr-consumer-key" secret="SHHHHH!!!!!!!!!!"
resourceName="Your Photos" resourceDescription="Your photos that you have uploaded to sparklr.com."
requiredToObtainAuthenticatedToken="false" authorities="ROLE_CONSUMER"/>
</oauth:consumer-details-service>
That's adding requiredToObtainAuthenticatedToken and authorities which will cause the consumer to be trusted and therefore all the validation process is skipped.
However I still get the login and confirmation screen from the Sparklr app. The current state of the official documentation is pretty precarious considering that the project is being absorbed by Spring so its filled up with broken links and ambiguous instructions. As far as I've understood, no changes are required on the client code so I'm basically running out of ideas. I have found people actually claiming that Spring-Oauth clients doesn't support 2-legged access (which I found hard to believe)
The only way I have found to do it was by creating my own ConsumerSupport:
private OAuthConsumerSupport createConsumerSupport() {
CoreOAuthConsumerSupport consumerSupport = new CoreOAuthConsumerSupport();
consumerSupport.setStreamHandlerFactory(new DefaultOAuthURLStreamHandlerFactory());
consumerSupport.setProtectedResourceDetailsService(new ProtectedResourceDetailsService() {
public ProtectedResourceDetails loadProtectedResourceDetailsById(
String id) throws IllegalArgumentException {
SignatureSecret secret = new SharedConsumerSecret(
CONSUMER_SECRET);
BaseProtectedResourceDetails result = new BaseProtectedResourceDetails();
result.setConsumerKey(CONSUMER_KEY);
result.setSharedSecret(secret);
result.setSignatureMethod(SIGNATURE_METHOD);
result.setUse10a(true);
result.setRequestTokenURL(SERVER_URL_OAUTH_REQUEST);
result.setAccessTokenURL(SERVER_URL_OAUTH_ACCESS);
return result;
}
});
return consumerSupport;
}
and then reading the protected resource:
consumerSupport.readProtectedResource(url, accessToken, "GET");
Has someone actually managed to make this work without boiler-plate code?