use of org.openstack4j.model.identity.v3.Credential in project openhab1-addons by openhab.
the class GCalEventDownloader method downloadEventFeed.
/**
* Connects to Google-Calendar Service and returns the specified Events
*
* @return the corresponding Events or <code>null</code> if an error
* occurs. <i>Note:</i> We do only return events if their startTime lies between
* <code>now</code> and <code>now + 2 * refreshInterval</code> to reduce
* the amount of events to process.
*/
private static Events downloadEventFeed() {
if (StringUtils.isBlank(calendar_name)) {
logger.warn("Login aborted no calendar name defined");
return null;
}
// authorization
CalendarListEntry calendarID = GCalGoogleOAuth.getCalendarId(calendar_name);
if (calendarID == null) {
return null;
}
DateTime start = new DateTime(new Date(), TimeZone.getTimeZone(calendarID.getTimeZone()));
DateTime end = new DateTime(new Date(start.getValue() + (2 * refreshInterval)), TimeZone.getTimeZone(calendarID.getTimeZone()));
logger.debug("Downloading calendar feed for time interval: {} to {} ", start, end);
Events feed = null;
try {
Credential credential = GCalGoogleOAuth.getCredential(false);
// set up global Calendar instance
Calendar client = new Calendar.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName("openHAB").build();
Calendar.Events.List l = client.events().list(calendarID.getId()).setSingleEvents(true).setTimeMin(start).setTimeMax(end);
// add the fulltext filter if it has been configured
if (StringUtils.isNotBlank(filter)) {
l = l.setQ(filter);
}
feed = l.execute();
} catch (IOException e1) {
logger.error("Event fetch failed: {}", e1.getMessage());
}
try {
if (feed != null) {
checkIfFullCalendarFeed(feed.getItems());
}
return feed;
} catch (Exception e) {
logger.error("downloading CalendarEventFeed throws exception: {}", e.getMessage());
}
return null;
}
use of org.openstack4j.model.identity.v3.Credential in project OpenRefine by OpenRefine.
the class FusionTableHandler method getFusionTablesService.
public static Fusiontables getFusionTablesService(String token) {
Credential credential = new GoogleCredential().setAccessToken(token);
Fusiontables fusiontables = new Fusiontables.Builder(GDataExtension.HTTP_TRANSPORT, GDataExtension.JSON_FACTORY, credential).setApplicationName(GDataExtension.SERVICE_APP_NAME).build();
;
return fusiontables;
}
use of org.openstack4j.model.identity.v3.Credential in project api-samples by youtube.
the class YouTubeAnalyticsReports method main.
/**
* This code authorizes the user, uses the YouTube Data API to retrieve
* information about the user's YouTube channel, and then fetches and
* prints statistics for the user's channel using the YouTube Analytics API.
*
* @param args command line args (not used).
*/
public static void main(String[] args) {
// These scopes are required to access information about the
// authenticated user's YouTube channel as well as Analytics
// data for that channel.
List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/yt-analytics.readonly", "https://www.googleapis.com/auth/youtube.readonly");
try {
// Authorize the request.
Credential credential = Auth.authorize(scopes, "analyticsreports");
// This object is used to make YouTube Data API requests.
youtube = new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName("youtube-analytics-api-report-example").build();
// This object is used to make YouTube Analytics API requests.
analytics = new YouTubeAnalytics.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName("youtube-analytics-api-report-example").build();
// Construct a request to retrieve the current user's channel ID.
YouTube.Channels.List channelRequest = youtube.channels().list("id,snippet");
channelRequest.setMine(true);
channelRequest.setFields("items(id,snippet/title)");
ChannelListResponse channels = channelRequest.execute();
// List channels associated with the user.
List<Channel> listOfChannels = channels.getItems();
// The user's default channel is the first item in the list.
Channel defaultChannel = listOfChannels.get(0);
String channelId = defaultChannel.getId();
PrintStream writer = System.out;
if (channelId == null) {
writer.println("No channel found.");
} else {
writer.println("Default Channel: " + defaultChannel.getSnippet().getTitle() + " ( " + channelId + " )\n");
printData(writer, "Views Over Time.", executeViewsOverTimeQuery(analytics, channelId));
printData(writer, "Top Videos", executeTopVideosQuery(analytics, channelId));
printData(writer, "Demographics", executeDemographicsQuery(analytics, channelId));
}
} catch (IOException e) {
System.err.println("IOException: " + e.getMessage());
e.printStackTrace();
} catch (Throwable t) {
System.err.println("Throwable: " + t.getMessage());
t.printStackTrace();
}
}
use of org.openstack4j.model.identity.v3.Credential in project api-samples by youtube.
the class AddSubscription method main.
/**
* Subscribe the user's YouTube account to a user-selected channel.
*
* @param args command line args (not used).
*/
public static void main(String[] args) {
// This OAuth 2.0 access scope allows for full read/write access to the
// authenticated user's account.
List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube");
try {
// Authorize the request.
Credential credential = Auth.authorize(scopes, "addsubscription");
// This object is used to make YouTube Data API requests.
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential).setApplicationName("youtube-cmdline-addsubscription-sample").build();
// We get the user selected channel to subscribe.
// Retrieve the channel ID that the user is subscribing to.
String channelId = getChannelId();
System.out.println("You chose " + channelId + " to subscribe.");
// Create a resourceId that identifies the channel ID.
ResourceId resourceId = new ResourceId();
resourceId.setChannelId(channelId);
resourceId.setKind("youtube#channel");
// Create a snippet that contains the resourceId.
SubscriptionSnippet snippet = new SubscriptionSnippet();
snippet.setResourceId(resourceId);
// Create a request to add the subscription and send the request.
// The request identifies subscription metadata to insert as well
// as information that the API server should return in its response.
Subscription subscription = new Subscription();
subscription.setSnippet(snippet);
YouTube.Subscriptions.Insert subscriptionInsert = youtube.subscriptions().insert("snippet,contentDetails", subscription);
Subscription returnedSubscription = subscriptionInsert.execute();
// Print information from the API response.
System.out.println("\n================== Returned Subscription ==================\n");
System.out.println(" - Id: " + returnedSubscription.getId());
System.out.println(" - Title: " + returnedSubscription.getSnippet().getTitle());
} catch (GoogleJsonResponseException e) {
System.err.println("GoogleJsonResponseException code: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("IOException: " + e.getMessage());
e.printStackTrace();
} catch (Throwable t) {
System.err.println("Throwable: " + t.getMessage());
t.printStackTrace();
}
}
use of org.openstack4j.model.identity.v3.Credential in project api-samples by youtube.
the class Captions method main.
/**
* Upload, list, update, download, and delete caption tracks.
*
* @param args command line args (not used).
*/
public static void main(String[] args) {
// This OAuth 2.0 access scope allows for full read/write access to the
// authenticated user's account and requires requests to use an SSL connection.
List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube.force-ssl");
try {
// Authorize the request.
Credential credential = Auth.authorize(scopes, "captions");
// This object is used to make YouTube Data API requests.
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential).setApplicationName("youtube-cmdline-captions-sample").build();
// Prompt the user to specify the action of the be achieved.
String actionString = getActionFromUser();
System.out.println("You chose " + actionString + ".");
Action action = Action.valueOf(actionString.toUpperCase());
switch(action) {
case UPLOAD:
uploadCaption(getVideoId(), getLanguage(), getName(), getCaptionFromUser());
break;
case LIST:
listCaptions(getVideoId());
break;
case UPDATE:
updateCaption(getCaptionIDFromUser(), getUpdateCaptionFromUser());
break;
case DOWNLOAD:
downloadCaption(getCaptionIDFromUser());
break;
case DELETE:
deleteCaption(getCaptionIDFromUser());
break;
default:
// All the available methods are used in sequence just for the sake
// of an example.
//Prompt the user to specify a video to upload the caption track for and
// a language, a name, a binary file for the caption track. Then upload the
// caption track with the values that are selected by the user.
String videoId = getVideoId();
uploadCaption(videoId, getLanguage(), getName(), getCaptionFromUser());
List<Caption> captions = listCaptions(videoId);
if (captions.isEmpty()) {
System.out.println("Can't get video caption tracks.");
} else {
// Retrieve the first uploaded caption track.
String firstCaptionId = captions.get(0).getId();
updateCaption(firstCaptionId, null);
downloadCaption(firstCaptionId);
deleteCaption(firstCaptionId);
}
}
} catch (GoogleJsonResponseException e) {
System.err.println("GoogleJsonResponseException code: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("IOException: " + e.getMessage());
e.printStackTrace();
} catch (Throwable t) {
System.err.println("Throwable: " + t.getMessage());
t.printStackTrace();
}
}
Aggregations