I managed to get an auth token from the AccountManager on Android for "writely" (Google Docs).
Now I want to get all documents from the user - but I have absolutley no idea how to do this.
There are a lot of libraries out there including the Google-Api-Java-Client but I have no clue how to use them. The picasa sample app also dosent help me... :(
Anyone, any idea?
Document List API V3 is what you can use - For details of using it and what to do with OAuth token etc take a look at here
DocService's JavaDocs
DocsService service = new DocsService("test-docs-service");
service.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());
try {
DocumentListFeed feed = service.getFeed(new URL("https://docs.google.com/feeds/default/private/full"), DocumentListFeed.class);
if(null != feed || feed.getEntries().size() > 0){
System.out.println("feed size = " +feed.getEntries().size());
for(DocumentListEntry entry : feed.getEntries())
{
System.out.println("filename = "+entry.getTitle().getPlainText());
}
}
else{
System.out.println("feed null OR size <=0");
}
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
There are several sample projects at the Google Code project of google-api-java-client here
Specifically for Android there are Calendar, Picasa and Tasks samples but there is also a Google Docs sample for command line Java. I would think it can be easily ported to Android.
Related
I've successfully created a demo in Android using keycloak openid-connect protocol configuration for SSO. Now I want to do with SAML protocol.
Details I used in openid-connect:
client_id
username
password
grant_type
client_secret
Now, when I changed from openid-connect to SAML inside keycloak dashboard, so client-secreted option got invisible.
So, in android I removed that variable, and also changed in URL from openid-connect to SAML. But getting error that Page not found
I seen lot of example, searched and imported github project as well, but wither I'll get demo with openid-connect or I'll get demo without using keyclaok.
I don't understand what else is required.
BTW, I followed this example for openid-connect and it is working as well: https://github.com/thomasdarimont/android-openid-connect/tree/feature/keycloak-oidc-demo
I'll share a bit code:
protected Boolean doInBackground(String... args) {
String authToken = args[0];
IdTokenResponse response;
showLog("Requesting ID token.");
try {
response = OIDCUtils.requestTokens(Config.tokenServerUrl,
Config.redirectUrl,
Config.clientId,
authToken);
} catch (IOException e) {
Log.e(TAG, "Could not get response.");
e.printStackTrace();
return false;
}
if (isNewAccount) {
createAccount(response);
} else {
setTokens(response);
}
return true;
}
Have a look, and there are really less examples on this things. Don't know why!
SAML is primarily for Browser Based Authentication (including Auth-Requests, Redirects, ...). So that's not really suitable for Android apps.
Do you have a good reason to use SAML and not stick to your (already working) OIDC solution?
I'm trying to use the AWS generated Android SDK for my API Gateway project. Based on the information on this Site I created a client interface with a API method like this:
#com.amazonaws.mobileconnectors.apigateway.annotation.Operation(path = "/events/bookingUpdate", method = "POST")
void bookingUpdatePost(BookingUpdate body);
So when I want to call my API I used the following code:
try {
clientInterface.bookingUpdatePost(generateBookingUpdateDeviceInformation(bookingUpdate));
} catch (ApiClientException e) {
Log.e(BuildConfig.APPLICATION_ID, e.getLocalizedMessage());
if (listener != null) {
listener.onBookingUpdatePostRequestFinished(new Error(e.getLocalizedMessage()));
}
}
is there any way to retrieve the APIResponse Headers from the amazon mobile connectors library?
There isn't a way to do so because it's not exposed externally. But you can use a generic invoker instead to achieve this.
hello i just learn API Twitter in android. At the start of my application, is shows 20 tweets with this URL
https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=name&count=20
I want to display the last 20 before 20 tweets that have been shown (with load endless) and all new tweet after tweet earlier 20 (with pull to refresh). but i don't know how the URL or method to get 20 last or newest tweet . how it's work ? sorry for my english.
You need this page: https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline found on this well documented page (https://dev.twitter.com/docs/api/1.1)
The URI you likely want though is:
https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=name&count=20&max_id=[lowest-id-from-last-batch]
If you're on Android I recommend using the Twitter4J library for easy Twitter API calls and response handling.
With use of Paging you can get the next 20 tweets (using Paging.page) or new tweets (using id's or time/since).
Code example for getting a Users timeline using Twitter4J in Android:
// Use as field
Twitter twitter;
// Get timeline
try {
if(twitter==null) {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(Constants.DEBUG)
.setOAuthConsumerKey("YOUR CONSUMER KEY")
.setOAuthConsumerSecret("YOUR CONSUMER SECRET")
.setApplicationOnlyAuthEnabled(true)
.setHttpConnectionTimeout(5000)
.setHttpReadTimeout(5000)
.setHttpStreamingReadTimeout(5000);
twitter = new TwitterFactory(cb.build()).getInstance();
twitter.getOAuth2Token();
}
return twitter.getUserTimeline("TwitterName", twitterPaging);
} catch (Exception e) {
e.printStackTrace();
}
I have an Android application with GAE server. I tried to authenticate the user as described on developers.google.com, I added the user parameter to the endpoint methods etc. I get a User which is not null, but this method getUserId() returns null. It is similar to this, rather old problem:
Function User.getUserId() in Cloud endpoint api returns null for a user object that is not null
But I still don't know how to work around it. How do you handle this error? Have you ever encountered it?
In android client here's what I did (its simplified) :
credentials = GoogleAccountCredential.usingAudience(getApplicationContext(), "server:client_id:" + WEB_CLIENT_ID);
credentials.setSelectedAccountName(accountName);
WarriorEntityEndpoint.Builder endpointBuilder = new WarriorEntityEndpoint.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credentials);
warriorEntityEndpoint = endpointBuilder.build();
new AsyncTask<Void, Void, Void>() {
#Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
try {
warriorEntityEndpoint.getWarrior().execute();
} catch (Exception e) {
}
return null;
}
}.execute();
And on GAE:
#Api(name = "warriorEntityEndpoint", namespace = #ApiNamespace(ownerDomain = "szpyt.com", ownerName = "szpyt.com", packagePath = "mmorpg.monsters"),
version = "version1",
scopes = {"https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile"},
clientIds = {Constants.ANDROID_CLIENT_ID, Constants.WEB_CLIENT_ID},
audiences = {Constants.ANDROID_AUDIENCE})
public class WarriorEntityEndpoint {
private static final Logger log = Logger.getLogger(WarriorEntityEndpoint.class.getName());
#ApiMethod(name = "getWarrior")
public WarriorEntity getWarrior(User user) throws OAuthRequestException, IOException {
log.log(Level.SEVERE, "this gives correct email: " + user.getEmail());
log.log(Level.SEVERE, "this is null: " + user.getUserId());
I have also another very important question: is this user authenticated, if getMail() gives me correct account, but getUserId() gives null? I read that user object should be null if it was not authenticated but I am not sure any more...
I'm using App engine SDK 1.8.7. I'm testing on a real device and backend deployed to GAE.
I asked the same question a while ago and got an answer. See link:
Function User.getUserId() in Cloud endpoint api returns null for a user object that is not null
The cause is a bug on appengine.
I guess there is no good solution for it right now. I store e-mail as a normal property and remove it from default fetch group, I use long as a primary key (generated by AppEngine) and I query the entity by the e-mail property. I don't like my solution, I'll accept ( and implement :) ) a better one if anyone can provide.
This is a known issue which has been filed with google, I've attached the issue link below.
There are two workarounds (1) save the user and read back from the store, if it refers to a valid account the user id will be populated (this sucks because you pay the saving / loading / deletion cost for each API access that is authenticated even if it is tiny, and obviously some performance cost) and (2) you could use the google+ ID but that is NOT the same as the user id.
This is extremely frustrating and there is currently no ETA as they are working on some fundamental issues with the auth design as far as I understand.
Please, vote for that issue by starring it. You can find all the information here
https://code.google.com/p/googleappengine/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Component%20Status%20Stars%20Summary%20Language%20Priority%20Owner%20Log&groupby=&sort=&id=8848
And here is the current formally approved workaround [(1) above], which you can also find in the link above, but for ease it's here: How can I determine a user_id based on an email address in App Engine?
For workaround (2) mentioned above, you can look at the first link, and go to post #39.
I wanna implement very efficient group chat in android. How can I do that? Please give me your best suggestions and also some step by step tutorial will help me in this.
I want to do peer to peer chat and also group chat. So Both type of implementations I wanna implement. Any SDK is available there? Or Any java lib are there?
Please give me your best suggestions.
Thanks,
Jay Patel
Start with checking out Google's own Google Cloud Messaging. This lets you push messages to other devices. After that, you can google and see if you find any examples or tutorials and you are good to go!
Here is a sample code of Android Chat SDK developed using Applozic backend server and Chat SDKS.
https://github.com/AppLozic/Applozic-Android-SDK
PS: I am from Applozic
You need to submit form like this for making a persistent group:
private void setConfig(MultiUserChat multiUserChat) {
try {
Form form = multiUserChat.getConfigurationForm();
Form submitForm = form.createAnswerForm();
for (Iterator<FormField> fields = submitForm.getFields(); fields.hasNext();) {
FormField field = (FormField) fields.next();
if (!FormField.TYPE_HIDDEN.equals(field.getType()) && field.getVariable() != null) {
submitForm.setDefaultAnswer(field.getVariable());
}
}
submitForm.setAnswer("muc#roomconfig_publicroom", true);
submitForm.setAnswer("muc#roomconfig_persistentroom", true);
multiUserChat.sendConfigurationForm(submitForm);
} catch (Exception e) {
e.printStackTrace();
}
}