Android Jtwitter, authentication issues - android

Hello I am having difficulty using the JTwitter functions to authenticate with my twitter application. I always get a "TwitterException"
Here is my method
OAuthSignpostClient oauthClient = new OAuthSignpostClient(consumerKey,
privateKey, "oob");
a) I don't know what the "oob" value SHOULD be, it is the "callbackURL" and in my application on twitter it says "callBack URL: none" so I have tried putting "none", "None", and null where "oob" with no differing results.
then the rest is boilerplate
Intent i = new Intent(Intent.ACTION_VIEW,
Uri.parse(oauthClient.authorizeUrl().toString()));
startActivity(i);
// get the pin
String v = oauthClient.askUser("Please enter the verification PIN from Twitter");
oauthClient.setAuthorizationCode(v);
// Store the authorisation token details for future use
String[] accessToken = oauthClient.getAccessToken();
// Next time we can use new OAuthSignpostClient(OAUTH_KEY, OAUTH_SECRET,
// accessToken[0], accessToken[1]) to avoid authenticating again.
EditText twitterText = (EditText)findViewById(R.id.twitterText);
twitterText.getText();
// Make a Twitter object
Twitter twitter = new Twitter(null, oauthClient);
// Print Daniel Winterstein's status
//System.out.println(twitter.getStatus("winterstein"));
// Set my status
twitter.setStatus(twitterText.getText());
at this point, I'm simply not sure on how to make this work. Wish I could be more verbose about it, but it has something to do with the authentication. Online things I've seen haven't been helpful

Try this as your callback url:
OAuthSignpostClient oauthClient =
new OAuthSignpostClient(consumerKey, privateKey, "callback://twitter");
Remember! After:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)));
Do the following
override onResume() to get the verification code
protected void onResume() {
super.onResume();
if (this.getIntent()!=null && this.getIntent().getData()!=null){
Uri uri = this.getIntent().getData();
if (uri != null && uri.toString().startsWith("callback://twitter")) {
//Do whatever you want
//usually use uri.getQueryParameter(someString);
//test what could be someString using Log.v("",uri.toString());
//you want the Authorization code which is a couple of numbers
//so you could use oauthClient.setAuthorizationCode(v);
//and finally initialise Twitter
}
}
}
You can use uri.getQueryParameterNames() to get the parameter String names.
#BobVork
I'd just like to add that you'll need to have a callback URL set in the Settings tab for your Twitter app (on twitter.com).
It doesn't even matter what you put in the field, but if it's empty, callback urls will not work.

I'm not sure that's the problem, but it seems like you never set the user name for the twitter object.

Well, I don't know how it is with the Jtwitter API and I don't know enough Java at this point to really understand the inner workings of this code, but have you tried, instead of NULL or None, to try ? instead. That is the callback used with the restful API when making calls from Javascript. Try it out.

Related

How to get shared Glympse link?

I have to implement live tracking using Glympse. In Glympse application you can share a link that link will show your current location. Now I have to get that link and send that link to server. I am searching for it but I am unable to get desired solution to get that link.
I have got examples form https://developer.glympse.com/docs/core/client-sdk/downloads link.
The GlympseCreateDemo shows the steps needed to get the link, but here are the key parts.
// Create the ticket for the given duration.
GTicket ticket = GlympseFactory.createTicket(duration, null, null);
// For the recipient list, we create a single "LINK" recipient. This
// means we want a recipient URL for the new Glympse without having
// the Glympse API actually send the invite out to anyone.
GInvite recipient = GlympseFactory.createInvite(GC.INVITE_TYPE_LINK, null, null);
ticket.addInvite(recipient);
// Call sendTicket to create the ticket and the recipient URL.
_glympse.sendTicket(ticket);
To listen for when the link is available
// The object you pass to this method must implement GEventListener
// In the demo this is done in GlympseCreateDemoActivity.java
ticket.addListener(this);
// Once the invite is ready you will get this event
#Override public void eventsOccurred(GGlympse glympse, int listener, int events, Object obj)
{
if (GE.LISTENER_TICKET == listener)
{
if (0 != (events & GE.TICKET_INVITE_CREATED))
{
GTicket ticket = (GTicket) obj;
// This string will contain the link that you can send to your server
String theUrlLink = ticket.getInvites().at(0).getUrl();
}
}
}

Autologin google, redirection webview not working

In Android i have a webview that lead to an google authentication form. When the authentication form is loaded in the webview it will call onReceivedLoginRequest:
public void onReceivedLoginRequest(final AuthenticationWebView client, final WebView view, final String realm,
final String account, final String args) {
...
}
When this method is called i get the Accounts stored on the device and let the user choose one and use that one to retrieve an authtoken:
mAccountManager.getAuthToken(account, mAuthToken, null, mWebViewActivity, this, null);
It all works perfectly fine (i think) and the next step looks good also:
final String result = bundle.getResult().getString(AccountManager.KEY_AUTHTOKEN);
if (result != null) {
// authentication succeeded, new url given as result for redirection
mWebView.loadUrl(result);
} else {
onLoginFailed();
}
A new method is called and returns the new url for redirection which i load in the webview. The result String returns a new adress which looks good but does nothing, it doens't log in but i don't get any message error either from the webview.
Url:
https://accounts.google.com/MergeSession?args=..&uberauth=WILL_NOT_SIGN_IN&source=AndroidWebLogin
I modified the url a bit with (triple)dots, don't know how secure it is and it was not such an interesting part of the url.
Anyone know why the url will not redirect me to the website behind it? When i use this url in my browser it recognizes my account, i only have to fill in my password and it redirects me correctly.
I use a native Android webview and i inject it with javascript but this only happens on the page after the login.
The settings i added to the webview are:
mSettings = getSettings();
mSettings.setJavaScriptEnabled(true);
mSettings.setDomStorageEnabled(true);
mSettings.setAllowFileAccess(true);
mSettings.setGeolocationEnabled(true);

Can not get Registration ID in Emulator

Hi I am running ADMMessenger sample application provided with SDK.
in which I am not able to get Registration ID in register() method of MainActivity.
Method is like this.
private void register()
{
final ADM adm = new ADM(this);
if (adm.isSupported())
{
if(adm.getRegistrationId() == null)
{
adm.startRegister();
} else {
// final MyServerMsgHandler srv = new MyServerMsgHandler();
// srv.registerAppInstance(getApplicationContext(), adm.getRegistrationId());
}
Log.v("log_tag","Reg_id:: "+adm.getRegistrationId());
}
}
in Log cat I am always getting Reg_id:: null
and onRegistrationError() method of SampleADMMessageHandler is calling.
and error at there is ERROR_SERVICE_NOT_AVAILABLE
I can not understand what is problem, please help me.
For the service to work correctly you need to be using the Kindle image (not a generic Android one) and also make sure you have logged into your account on the device (pull down the status bar at the top and ensure you have selected an account)

Login flow for Gigya in mobile app with custom login UI

I'm developing an Android app using Gigya to allow people to register using Facebook and Twitter; in parallel another developer is doing the same thing in iOS. We want to implement custom login UI.
The standard method uses Gigya's own UI and is documented here:
http://developers.gigya.com/035_Mobile_SDKs/020_Android#Logging_in_the_User
Beneath, it simply suggests:
If you wish to implement the graphic design by yourself, use the login method instead.
The standard login method calls a dedicated post-login callback with an onLogin(...) method and all subsequent flows are described as stemming from this event. The other login method calls a standard onGSResponse(...) callback; it's not clear how the response can be used to construct a user so I've set up my implementation to call socialize.getUserInfo. Attempts to call either method have resulted in lots of unusual errors.
As per the Gigya instructions I'm starting up with
mGSAPI = new GSAPI(GIGYA_APP_KEY, this);
mGSAPI.setAPIDomain("eu1.gigya.com");
in onCreate(...) (where GIGYA_APP_KEY is a value copied from our console). I'm calling setAPIDomain because we were getting an invalid data center error (albeit with a 500001 code, not a 301001 code!), which this has fixed.
Facebook login goes through the login flow as I'd expect and then comes back with error 400093 (which the docs tell me is an invalid API parameter, and has the message " Missing parameter: client_id").
Twitter login comes back with 206002, " Account Pending Verification", which seems to make sense; I then call
mGSAPI.sendRequest(
"getUserInfo",
null, //parameters
true, //use HTTPS
this, //the callback
null //a context object
);
and this gives me the error:
Missing required parameter: No secret or signature were provided. Request could not be verified.
The documentation for socialize.getUserInfo suggest a UID is required for web apps, but not for native ones. It mentions no other mandatory fields. I am a bit stuck ... shouldn't the GSAPI object be handling verification, as it's initialized with the API key?
I can give you some direction at a very high level for integrating GIGYA. (Code below is not verbatim) Hopefully it is somewhat helpful.
For a private Android app I had created a Manager object (GigyaManager) that maintained a singleton instance of the GSAPI object.
This singleton GigyaManager was initialized in my application object:
public static GigyaManager getInstance(String apiKey, Context context) {
mGSAPI = new GSAPI(apiKey, context);
}
My GigyaManager class also had a wrapper method for handling the login w/social services:
public void loginWithSocialService(GigyaSocialProvider provider, GSResponseListener listener) throws Exception {
// did the user attempt a social login, and bail out on the registration
// phase?
if (GigyaManager.getInstance().getGSAPI().getSession() != null) {
logout();
}
GSObject providerArgs = new GSObject();
providerArgs.put(GigyaManager.GIGYA_ARG_PROVIDER, provider.name().toLowerCase());
mGSAPI.login(providerArgs, listener, null);
}
This was fired from an onClick listener in a fragment that contained a "login" button:
GigyaManager.getInstance("appKey", getActivity()).loginWithSocialService(GigyaSocialProvider.FACEBOOK, this);
That fragment had to implement GSResponseListener that has the callbacks to deal with whether the login was successful or not:
#Override
public void onGSResponse(String method, GSResponse response, Object context) {
if (!method.equalsIgnoreCase("login") || response.getErrorCode() != 0) {
return;
}
GIGYAResponseWrapper resp = new GIGYAResponseWrapper(response.getResponseText());
// user is attached to login provider?
if (resp.isIsAttached()) {
// start some sort of loader or asynctask to get information about user account
// connected to GIGYA social login
Bundle args = new Bundle();
args.putString(ARG_UID, resp.getUid());
args.putString(ARG_UID_SIGNATURE, resp.getUidSignature());
args.putString(ARG_SIGNATURE_TIMESTAMP, resp.getSignatureTimestamp());
args.putString(ARG_SOCIAL_NICKNAME, resp.getNickname());
} else {
// login success, but this social account is not associated with anything in GIGYA
}
}

phonegap parsing incoming data to application

Using PhoneGap I am opening an application on Android from a link in an email using an intent specified in the Manifest file. This is working fine.
What I need to do now is parse in some data to the application that is opened, the data I am retrieving from the URL query params, this is working fine I am reading the URL that is clicked in the email within the onCreate(Bundle savedInstanceState) method thus:
super.loadUrl("file:///android_asset/www/index.html");
System.out.println("- start intent -");
final Intent intent = getIntent();
if(intent != null && intent.getDataString() != null){
System.out.println("- data string:"+intent.getDataString());
String url = intent.getDataString();
this.sendJavascript("testMethod('"+url+"');");
System.out.println("- finished method call");
}
If you look at the code above the system outs are all output as expected and the data string is exactly as expected but the testMethod(url), which is in my index.js file, never gets called.
Even when I do a simple method thus
function testMethod(url){
alert("************************ alert");
console.log("******************** log")
console.warn("******************** warn")
console.info("******************** info")
console.error("******************** error")
}
None of the console calls or the alert are made.
So to me it seems that the sendJavascript method is not being executed or called.
Am I missing something?
In the end I could not get this to function at all. What I am trying to acheive is pass a value in when the application is loaded from a URL. I acheived this by changing the URL if there is an intent and adding query parameters to the loadUrl. Then in the index.js I have checked for window.location.search and then called an extra function if a specific query param is found like this.
if(intent != null && intent.getDataString() != null){
super.loadUrl("file:///android_asset/www/index.html?register=true");
}
else{
super.loadUrl("file:///android_asset/www/index.html");
}
Then in the Javascript
if(window.location.search === "?register=true"){
handleOpenURL("my/url");
}

Categories

Resources