Google Calendar(sharing) - java

I'm working with a Google Apps application. Actually, I want to the access another id without using a password for that. I used OAuth and it's working well. But I am not able to share the particular person's calendar. I tried the following code.
GoogleOAuthParameters oauthParam=new GoogleOAuthParameters();
oauthParam.setOAuthConsumerKey("xxxx.com");
oauthParam.setOAuthConsumerSecret("xxxxxxxxxxxxxxxxxxx");
oauthParam.setScope("http://www.google.com/calendar/feeds/");
URL feedUrl = new URL("http://www.google.com/calendar/feeds/default/owncalendars full?xoauth_requestor_id=user#example.com");
CalendarService service=new CalendarService("calendar");
service.setOAuthCredentials(oauthParam,new OAuthHmacSha1Signer());
AclEntry entry = new AclEntry();
entry.setScope(new AclScope(AclScope.Type.USER,"any.user"));
entry.setRole(CalendarAclRole.READ);
AclEntry insertedEntry = service.insert(feedUrl, entry);
For this code I got the error:
com.google.gdata.util.InvalidEntryException: Bad Request
Calendar entry does not contain title
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:558)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563)

Inserting ACL entries instead of Calendar entries into the own calendars feed is not a good idea. Also, this API is now deprecated, use http://code.google.com/apis/calendar/v3/getting_started.html for the reference.

Related

Guide about twitter login in web without using any third party library

I find a way to implement twitter login with github twitter4j but I want to implement it without using any third party library. With the twitter document, I am not able to understand what should I do for it. From where I can get oauth_nonce, oauth_timestamp & oauth_signature's value? Please suggest me a good way to implement twitter login in web.
Please suggest me a good way to implement twitter login in web.
The Twitter developer documentation says this:
"Most developers will not need to work with the details of OAuth, since Twitter Client Libraries already implement the protocol. It is strongly recommended to use one of these libraries. "
If you choose to ignore that advice, then the same page has links to other pages that explain OAuth, explain various ways to get tokens, and explain how to ad authentication details to your requests.
I am myself the developer of a ThirdParty library and I will definitely advise to use them. Twitter authentication has multiple problems to consider.
Anyway here is an answer for you.
// oauth_nonce
var oauth_nonce = new Random().Next(123400, 9999999).ToString(CultureInfo.InvariantCulture);
// oauth_timestamp
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
var oauthTimestamp = Convert.ToInt64(ts.TotalSeconds).ToString(CultureInfo.InvariantCulture);
Signature is a bit more complicated. You need to extract all the params of your query. Order them by name, Append all of them into a string separated with '&' (lets call it URL_PARAMETERS).
Then create a string as followed {HTTP_METHOD}&{BASE_URL}&{URL_PARAMETERS}
Now you simply have to compute the Hash of the previous value with the oauth_secret_key (from Twitter app).
And not you can simply do oauth_signature = Http.UrlEncode(Convert.ToBase64(<HASH>)).
Also don't forget
var oauth_signature_method = "HMAC-SHA1";

How to view a public Google Calendar via an Android Application

I must've gone through ever Stack Overflow question based on the Google Calendar so far with no luck what so ever. I've been trying this for hours now and got little to no results at all.
I'm a pretty new programmer with Java and Android, with quite little experience out of the field as it is. Basically the main problem I am having is with viewing another user's Google Calendar which is set to public.
At the moment, from the Google tutorials and other sites I've managed to get the calendar showing, which is pretty simple enough. It'll just load up and show the current user's calendar. Which can literally be done with (with a simple button in the layout).
public void onClick(View view) {
// A date-time specified in milliseconds since the epoch.
long startMillis = System.currentTimeMillis();
Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
builder.appendPath("time");
ContentUris.appendId(builder, startMillis);
Intent intent = new Intent(Intent.ACTION_VIEW).setData(builder.build());
startActivity(intent);
}
Obviously this doesn't pass in any user data for the public account or anything, I've been reading through the Calendar Provider Developer guides within the Google tutorials. I've tried to set up the account details thing, but it just never works. I've tried to do it as a Sync Adapter, but honestly I just know I'm not doing it right. I don't know if I really even need to use a Sync Adapter as all I want to do is literally see the events, not modify anything or update anything.
I am using API 14+ and want to user the Calendar Provider etc. It looks simple enough but I've been bashing my head against this for a few days and put a lot of hours into it and seemingly nothing I do works. At least I've got some sort of calendar opening but it's not what I want.
Is it all just down to the sync adapter? If so how will I be able to call a calendar? Another question similar had
private static Uri buildCalUri() {
return CalendarContract.Calendars.CONTENT_URI
.buildUpon()
.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
.appendQueryParameter(Calendars.ACCOUNT_NAME, ACCOUNT_NAME)
.appendQueryParameter(Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL)
.build();
}
I'm hoping this is something similar to what I need but I'm very unsure. In the developer tutorial ACCOUNT_TYPE_LOCAL was important if the account wasn't on the device
Any help will be greatly appreciated!
If you are looking to integrate the public Google Calendar (www.google.com/calendar) with your Android Application, you have to use the Google Calendar API.
The easiest method would be download the Google Calendar Client Library from here and then use the API Reference here. In the Client Library Page, you want to download "Google APIs Client Library for Java (rc)" package to integrate into your Android App.
You will first need to go to API Console to create an App with Calendar API Access .
If you do not want to use the native library, you can even do it using REST API (use HTTP GET & POST Commands), example App here
Hope this helps.
For anybody that has followed the Android Developer API example, but still can't find how to add a public calendar. Try out
CalendarListEntry gracieCal = new CalendarListEntry();
gracieCal.setId("your-public-calendar-id");
mService.calendarList().insert(gracieCal);
Events events = mService.events().list(gracieCal.getId())
.setMaxResults(10)
.setTimeMin(new DateTime(System.currentTimeMillis()))
.setOrderBy("startTime")
.setSingleEvents(true)
.execute();
List<Event> items = events.getItems();
'mService' is the com.google.api.services.calendar.Calendar instance that you should have already created. (see the api tutorials mentioned by the other answer)
'your-public-calendar-id' can be found in the settings for your public google calendar.

How to publish a post using Facebook4J so that others can see it

I use this code to publish a post on my Facebook wall from Java:
facebook.postStatusMessage("Hello World from Facebook4J.");
However, there is a problem: only I can see this post, my friends cannot.
How can it be visible to my friends?
With postStatusMessage() method, you publish a post using your default privacy setting.
Try to use postFeed() method with privacy parameter.
To post to all friends example:
PrivacyParameter privacy = new PrivacyBuilder().setValue(PrivacyType.ALL_FRIENDS).build();
PostUpdate postUpdate = new PostUpdate(new URL("http://facebook4j.org"))
.picture(new URL("http://facebook4j.org/images/hero.png"))
.name("Facebook4J - A Java library for the Facebook Graph API")
.caption("facebook4j.org")
.description("Facebook4J is a Java library for the Facebook Graph API. This library provides the ease of use like Twitter4J. Facebook4J is an unofficial library.")
.privacy(privacy);
String postId = facebook.postFeed(postUpdate);
where in is InputStream your photo
Media media = new Media("", in);
PhotoUpdate photoUpdate = new PhotoUpdate(media);
postId = facebook.postPhoto(photoUpdate);

UnboundID LDAP - how to set flags in userAccountControl attribute

i am using UnboundID LDAP SDK for ActiveDirectory management, and i want to create new user. I am able to create connection to ActiveDirectory and add new user with some attributes, but i dont know how to work with attribute userAccountControl. This attribute is used by ActiveDirectory to store some flags, and i don't know how to set these flags using UnboundID LDAP SDK. Thank for any help.
Some information about attribute userAccountControl
http://msdn.microsoft.com/en-us/library/windows/desktop/ms680832(v=vs.85).aspx
I found out that i had some path wrong, here is code for modification userAccountControl
Modification mod = new Modification(ModificationType.REPLACE, "userAccountControl", usr.getUAC().toString());
ModifyRequest req = new ModifyRequest(userCN + userOU, mod);
LDAPResult modResult = connection.modify(req);
The userAccountControl is a bit mask so it is necessary to set is as an integer.
We have some of the values and information documented here:
http://ldapwiki.willeke.com/wiki/User-Account-Control%20Attribute%20Values
Might help if you said what you were trying to set in userAccountControl and provided the code you are using.

Google Calendar

I'm developing one web application project using java for education industry.In this Admin have all rights to access the google services of other users like A,B,C..... for this is use OAuth.Then i tried Admin want to share user A's calendar to user B using OAuth.But i got stuck in this step. Is it possible Plz Help me
Thanks
Regards
Sharun
I believe you want to use Access Control Lists (ACLs), see the docs. The Java example code at this URL for the task you mention is pretty simple:
AclEntry entry = new AclEntry();
entry.setScope(new AclScope(AclScope.Type.USER, "jdoe#gmail.com"));
entry.setRole(CalendarAclRole.READ);
URL aclUrl =
new URL("http://www.google.com/calendar/feeds/jo#gmail.com/acl/full");
AclEntry insertedEntry = service.insert(aclUrl, entry);
and what it does is, and I quote:
This code allows jdoe#gmail.com to
have read-only access to
jo#gmail.com's calendar.
There's more where this came from (e.g., upgrading a user's role in an ACL above the read-only access granted in this example), and I think it's a good idea to read the whole page.

Categories