Google Calendar API v3 - Update Event - ruby-on-rails

I'm using google-api-ruby-client for working with Google Calendar API v3.
The only problem I'm facing is with updating an event twice.
It has been discussed here before (Google Calendar api v3 re-update issue) but without ruby client and no answer.
When I add a new event I get an ID and an ETAG. I use ID to update the event and I get a new ETAG. Now If I try to update 2nd time, it doesn't update and sends 400 error with message "Invalid Value".
I have to send latest ETAG when updating 2nd time but I'm not sure how to send that when working with google-api-ruby-client.
Here's the code:
event = {
'summary' => "Summary",
'location' => "Location",
'description' => "Description",
'start' => {
'dateTime' => #entry.from_date
},
'end' => {
'dateTime' => #entry.to_date
}
}
result = client.execute(:api_method => service.events.update,
:parameters => {'calendarId' => #entry.calendar.gid, 'eventId'=>#entry.gid},
:body => JSON.dump(event),
:headers => {'Content-Type' => 'application/json'})

The docs are really sketchy on this but it seems you have to increment the sequence property each time you do an update. It's a revision control mechanism.
http://www.kanzaki.com/docs/ical/sequence.html

Related

Send google analytics event in ruby

I have the following code for google analytics real time, in ruby:
# Execute the query
sa_visitCount = client.execute(:api_method => analytics.data.realtime.get, :parameters => {
'ids' => "ga:" + saprofileID,
'metrics' => "ga:activeVisitors",
})
Followed with:
send_event('sa_realtimevisitors', current: sa_visitCount.data.rows)
This works great and returns an active visitor count.
Now I am trying to change this to return an event I have created on google analytics. Here is what the event looks like. You find this under Real-Time and Events. I am trying to use the Event Category "Ad" Listed as #2 in the screenshot.
The code I am using to attempt this in ruby is as follows.
phonehub_visitCount = client.execute(:api_method => analytics.data.realtime.get, :parameters => {
'ids' => "ga:" + saprofileID,
'metrics' => "ga:sessionsWithEvent",
})
Followed with:
send_event('phonehub_event', current: phonehub_visitCount.data.rows)
This returns nothing. I'm still using the original GA ID, however I'm trying to tell it to look at the event I created. Is there a way in ruby to make the GA realtime return the results from the event? Ideally the solution I'm looking for is to return real time active visitors on the event I have made.
After further research I found that I had to specify v3 in the api method.
So instead of phonehub_visitCount = client.execute(:api_method => analytics.data.realtime.get, :parameters => {
I had to use
api_method = client.discovered_api('analytics','v3').data.ga.get
Then add
phonehub_visitCount = client.execute(:api_method => api_method, :parameters => {

Eventbrite API create private event

I'm using Eventbrite API to create events from my application, what I need are private events and I create them with this code:
$event_params = array(
'title' => $event->name,
'description' => $event->description,
'start_date' => $event->start_at,
'end_date' => $event->end_at,
'timezone' => 'Europe/Paris',
'privacy' => '0',
'venue_id' => $venue_id,
'organizer_id' => $organizer_id,
'capacity' => $event->capacity,
'currency' => 'EUR',
'locale' => 'fr_FR',
'status' => $event->status,
'custom_header' => '<img src="'.asset($event->placeholder_img).'" width="100%"/>'
);
$resp = $this->eb_client->event_new($event_params);
so the event is created in Eventbrite but it can be shared via social media: http://prntscr.com/6w0b20 and I don't want this thing, I was wondering if this social sharing could be avoid via Eventbrite API.
Thank you,
Adrian
Answered in our forum, but I'll leave it here as well.
By setting the 'event.shareable' parameter to False you will be able to shut off this feature via the API.
You can see the request parameters for Event Details (event_new's parity endpoint) here http://www.eventbrite.com/developer/v3/endpoints/events/#ebapi-post-events

Google + moments not visible on user's feed using google_api_client gem

I am trying to post to user's stream using google api client, I am using below mentioned code
require 'google/api_client'
require 'google/api_client/client_secrets'
require 'google/api_client/auth/installed_app'
client = Google::APIClient.new
client.authorization.client_id = CLIENT_ID
client.authorization.client_secret = CLIENT_SECRET
client.authorization.access_token = USER_ACCESS_TOKEN
plus = client.discovered_api('plus', 'v1')
moment = {
:type => 'http://schemas.google.com/AddActivity',
:target => { :id => Time.now.to_i.to_s,
:description => 'well this is it',
:name => 'Well this is it'
}
}
req_opts = { :api_method => plus.moments.insert,
:parameters => { :collection => 'vault', :userId => 'me', },
:body_object => moment
}
response = client.execute!(req_opts).body
After executing the above code I am getting the response as follow
{"kind"=>"plus#moment",
"type"=>"http://schemas.google.com/AddActivity",
"target"=>{"kind"=>"plus#itemScope", "id"=>"1422863753", "description"=>"well this is it", "name"=>"Well this is it"}}
But when I go to user's profile then I am not able to see this activity anywhere in profile.
Note: The moment methods do not write directly to a user's Google+ stream. They instead write to a user's profile, and are not necessarily viewable by others depending on the user's preferred sharing settings.
Manage app activities in Google
To find where moments are visible, view the profile about page and look for the "Apps with Google+ Sign-in" section.

"Unexpected. Please try again." error when performing simple query

I keep receiving a status 500 error: "Unexpected. Please try again" message when I perform a query using the Ruby client. This query works when I input this into the API explorer on the google site.
Here is the code:
result = client.execute(
:api_method => bigquery.jobs.query,
:parameters => {"projectId" => "projectId"},
:body_object => { "kind" => "bigquery#queryRequest", "query" => "SELECT date FROM
[google.com:adsense-reports:Reports.DailyAdUnitReport] WHERE date = CURRENT_DATE()"}
)
Is there an error in this syntax?
When you say {"projectId" => "projectId"} did you actually have your project-ID in the code and redacted it here or did you pass the string "projectID" there?
If the latter is true, you might want to substitute that to pass your project-id which is a string that can be found in the project console here: https://cloud.google.com/console/project

Unable to retrieve video metrics using Youtube Analytics API

According to the Youtube Analytics API documentation (https://developers.google.com/youtube/analytics/v1/available_reports), it looks like you should be able to retrieve metrics for specific videos using the "video" dimension. I am able to get all other metrics successfully - either specifying dimensions like "day" and "country" or supplying no dimension at all.
But when I change the dimensions value to "video", I get a 400 error code with the message "The query is not supported. Check the documentation for supported queries." This is a channel report - not a content owner report - but according to the documentation, this should be a valid report request. I've even tried limiting the result set with a number of extra parameters like start-index, max-results, and sort.
WORKS
client.execute(:api_method => "youtubeAnalytics.reports.query",
:parameters => {'ids' => "channel==##USER_ID##",
"start-date" => "2012-01-01", "end-date" => "2012-02-01",
"metrics" => "views"})
client.execute(:api_method => "youtubeAnalytics.reports.query",
:parameters => {'ids' => "channel==##USER_ID##",
"start-date" => "2012-01-01", "end-date" => "2012-02-01",
"metrics" => "views",
"dimensions" => "day"})
DOES NOT WORK - returns 400 error
client.execute(:api_method => "youtubeAnalytics.reports.query",
:parameters => {'ids' => "channel==##USER_ID##",
"start-date" => "2012-01-01", "end-date" => "2012-02-01",
"metrics" => "views",
"dimensions" => "video"})
client.execute(:api_method => "youtubeAnalytics.reports.query",
:parameters => {'ids' => "channel==##USER_ID##",
"start-date" => "2012-01-01", "end-date" => "2012-02-01",
"metrics" => "views",
"dimensions" => "video",
"start-index" => 1,
"max-results" => 5,
"sort" => "views"})
Has anyone been able to make a successful request for a channel report for video level details?
So the following does work:
channel==USER_ID
start-date=YYYY-MM-DD
end-date=YYYY-MM-DD
metrics=views
dimensions=video
max-results=10
sort=-views
The important thing is that you need to sort by descending views if you want to run a dimensions=video report, and you can only retrieve at most 10 results. This is explained in the second table at
https://developers.google.com/youtube/analytics/v1/available_reports#Channel_Reports
The 10 max results mentioned in their docs, ordered by decreasing views, is obviously an artificial limit imposed by the backend source for Analytics data, but that's all the API could support before. Google just updated it so you can get up to 200 video results - https://developers.google.com/youtube/analytics/revision_history
If you're in a scenario where you want to get Analytics data for arbitrary videos in a given account, not just the 10 with the most views, you need to set the dimension to something other than video, and then run a report with a filter= set to each video id in your account that you're interested in. Again, this might change in the future, but as of right now the Analytics API isn't suited for getting a huge dump of data for every single video in an account in a single API call.
Note that a recent change, in Aug 2014, to YouTube API now allows fetching metrics for up to 200 videos per API call.
See https://developers.google.com/youtube/analytics/revision_history for Aug 28, 2014

Resources