Editing Google Calendar Event Meets URI With External Link via API - ruby-on-rails

I've had code that has been working for the last year or so, that adds a new Google Meets Entry Point with my own custom URI to the Google Calendar Event via the Google Calendar API.
For example if I click on "Join with Google Meet" below it does not go to a meets.google.com link like usual, because I replaced it with my own custom link.
Unfortunately for some reason in the past couple weeks this stopped working. Now when my code tries to edit the URI for the meet, it returns this error: Google::Apis::ClientError (invalid: Invalid Value). I haven't changed the code in months and this only started happening recently.
Here is what the code looks like:
def update_event_meet_url(service, event, send_updates = "all")
entry_points = [
Google::Apis::CalendarV3::EntryPoint.new(
entry_point_type: "video",
label: meeting_url,
uri: meeting_url,
),
]
if original_phone_info.present?
entry_points << Google::Apis::CalendarV3::EntryPoint.new(
entry_point_type: original_phone_info["entry_point_type"],
label: original_phone_info["label"],
uri: original_phone_info["uri"],
pin: original_phone_info["pin"],
region_code: original_phone_info["region_code"],
)
end
event_changes = {
conference_data: Google::Apis::CalendarV3::ConferenceData.new(entry_points: entry_points),
}
updated_event = Google::Apis::CalendarV3::Event.new(event_changes)
service.patch_event(
gcalendar_id,
event.id,
updated_event,
conference_data_version: 1,
send_updates: send_updates,
)
end
I know the problem is with the video entry point because I replaced the meeting_url with a working https://meets.google.com link and it worked. But if I try anything else that is not meets.google.com it errors.
I'm using this Ruby gem https://github.com/googleapis/google-api-ruby-client.
Any help would be appreciated! Thanks!

Contacted google support and looks like there was a recent release that changed the behavior of conferenceData.conferenceSolution.key.type. More info here: https://developers.google.com/calendar/releases#january_11_2021)we
Basically I needed to change my conference solution key type to addOn instead of hangoutsMeet. The subsequent problem I had was that I still needed a hangoutsMeet link, since the third party url I'm using would eventually redirect to the meets.google.com link. And the only way to get a hangoutsMeet link is to create the initial event with conferenceData.conferenceSolution.key.type = hangoutsMeet.
So what I did was create the google event with conferenceData.conferenceSolution.key.type = 'hangoutsMeet' and then I did a subsequent patch_event call that set the initial hangoutsMeet conference solution to null and created a new conferenceSolution of type addOn. That way I could store the original meets.google.com link and then use that link for the redirect from my third party link.
def update_event_meet_url(service, event, send_updates = "all")
entry_points = [
Google::Apis::CalendarV3::EntryPoint.new(
entry_point_type: "video",
label: meeting_url,
uri: meeting_url,
),
]
conference_solution_key = Google::Apis::CalendarV3::ConferenceSolutionKey.new(type: "addOn")
conference_solution =
Google::Apis::CalendarV3::ConferenceSolution.new(key: conference_solution_key)
event_changes = {
conference_data: Google::Apis::CalendarV3::ConferenceData.new(
conference_solution: conference_solution,
entry_points: entry_points,
create_request: nil,
),
}
updated_event = Google::Apis::CalendarV3::Event.new(event_changes)
service.patch_event(
gcalendar_id,
event.id,
updated_event,
conference_data_version: 1,
send_updates: send_updates,
)
end

Related

Instagram Graph API Recent Search result returns blank data

thank you for reviewing my question.
I've been using Instagram Graph API to make some hashtag recent search.
# Retrieve Keys
key = json.loads(keycontent)
HASHTAG_ID = key['HASHTAG_ID']
USER_ID = key['USER_ID']
ACCESS_TOKEN = key['ACCESS_TOKEN']
CURSOR = key['CURSOR']
topic = 'HASHTAG_ID' # Job
# Get Request URL
url = f"https://graph.facebook.com/{HASHTAG_ID}/recent_media?fields=id,permalink,caption,media_url&limit=50&user_id={USER_ID}&access_token={ACCESS_TOKEN}"
if CURSOR != "":
url = url + '&after=' + CURSOR
res = requests.get(url)
print(res.json()[‘data’])
It works quite successfully, but problem turns out that it starts to return blank data after calling the function several times. The data I am receiving at the moment are equal to either of the followings:
{"data": []}
{
"data": [
],
"paging": {
"cursors": {
"after": "NEXT_CURSOR"
},
"next": "LINK_WITH_NEXT_CURSOR"
}
}
I've checked several known issues, and the list of what I've checked are stated below.
It is not the permission issue. I've checked all the permissions related, and it is confirmed that the app has all permission it needs.
The app is certainly below the execution limit. Actually, it is mostly even below half of it.
The app is also below the number of hashtags I can search. I've called significantly lower than 30 hashtags within 7 days.
So, I'd like to know if there are potential reasons that I am having blank data for Instagram Graph API call.
Thank you in advance.

AWS QuickSight rails integration authorization code error

I have a rails application that needs to add QuickSight. Found that for these purposes it is necessary to use the get_dashboard_embed_url method. This method returns me the URL, but following it (manually, through an iframe tag) I get this error text
Embedding failed because of invalid URL or authorization code. Both of these must be valid and the authorization code must not be expired for embedding to work.
Where can I find the authenticate code? How can I get it? Thanks for your help
This is how i fetch the url
credential_options = {
client: Aws::STS::Client.new(region: ENV['AWS_REGION']),
role_arn: ENV['QUICK_SIGHT_ROLE_ARN'],
role_session_name: self.user_email
}
assume_role_credential = Aws::AssumeRoleCredentials.new(credential_options)
qs_client = Aws::QuickSight::Client.new({
credentials: assume_role_credential,
region: ENV['AWS_REGION']
})
begin
qs_client.register_user({
identity_type: 'IAM', # accepts IAM, QUICKSIGHT
email: self.user_email,
user_role: 'READER', # accepts ADMIN, AUTHOR, READER, RESTRICTED_AUTHOR, RESTRICTED_READER
iam_arn: ENV['QUICK_SIGHT_ROLE_ARN'],
session_name: self.user,
aws_account_id: ENV['AWS_ACCOUNT_ID'],
namespace: 'default'
})
rescue
end
options = {
aws_account_id: ENV['AWS_ACCOUNT_ID'],
dashboard_id: ENV['QUICK_SIGHT_DASHBOARD_ID'],
identity_type: 'IAM',
session_lifetime_in_minutes: 300,
undo_redo_disabled: false,
reset_disabled: false
}
qs_client.get_dashboard_embed_url(options, {}).embed_url
And how i try to display
iframe src=#url class='w-100 h-100' style='min-height: 500px;'
At the first, sorry for my weak english, but i hope that you'll understand what i mean
Ok, after completing these points, everything began to work for me. Also read "Underwater rocks", this is very important points list which will save you tons of time
Replace my code in question with this
def fetch_url # this method fetch embed dashboard url
credential_options = {
client: Aws::STS::Client.new(
region: ENV['AWS_REGION'],
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
),
role_arn: ENV['QUICK_SIGHT_ROLE_ARN'],
role_session_name: self.user_email # This is attr_accessor :user_email
}
assume_role_credential = Aws::AssumeRoleCredentials.new(credential_options)
qs_client = Aws::QuickSight::Client.new({
credentials: assume_role_credential,
region: ENV['AWS_REGION']
})
begin
qs_client.register_user({
identity_type: 'IAM', # accepts IAM, QUICKSIGHT
email: self.user_email,
user_role: 'READER', # accepts ADMIN, AUTHOR, READER, RESTRICTED_AUTHOR, RESTRICTED_READER
iam_arn: ENV['QUICK_SIGHT_ROLE_ARN'],
session_name: self.user_email,
aws_account_id: 'ENV['AWS_ACCOUNT_ID']',
namespace: 'default'
})
rescue
end
options = {
aws_account_id: ENV['AWS_ACCOUNT_ID'],
dashboard_id: ENV['QUICK_SIGHT_DASHBOARD_ID'],
identity_type: 'IAM',
session_lifetime_in_minutes: 300,
undo_redo_disabled: false,
reset_disabled: false
}
qs_client.get_dashboard_embed_url(options).embed_url
end
Go to Manage QuickSight panel https://your-quicksight-region(us-east-2 for example).quicksight.aws.amazon.com/sn/admin#users and click on "Manage permissions" button (button is placed above of the table with users)
On the new page click on "Create" button and select "Sharing dashboards" checkbox. Set the name of the permission, click on the "Create" button
In your controller action: #url = fetch_url # fetch_url - method from 1 point
Add to your view: iframe src=#url OR you can use a amazon-quicksight-embedding-sdk but for me the iframe works pretty well
Underwater rocks
Remember that dashboard url (which you are get with this method qs_client.get_dashboard_embed_url(options).embed_url) can be used only once, i.e. you can't open two browsers tabs with the same URL. When you are will pass this URL to iframe, this URL will cease to be working and you will no longer be able to use it in others browser windows or others iframe's
Add your app domain to whitelist domains on the QuickSight. You can do it in the Manage QuickSight panel https://your-quicksight-region.quicksight.aws.amazon.com/sn/admin#embedding
!!!IMPORTANT!!! if you are trying to embed dashboard to your localhost:your_server_port_number rails server, then you will always get the error message into the iframe (but if you go to this URL through the address bar of the browser, then you should see your dashboard (comment out / remove the iframe so it doesn't use the link, because every embedded dashboard url is disposable)). This is because localhost:your_server_port_number is not provided in the whitelist (Underwater rocks p.2). For resolving this issue and testing your work you can use ngrok (maybe it's available only for macOS, i'm not sure).
When you'll download the ngrok open your terminal and run command
$ ./path_to_ngrok_script/./ngrok http your_server_port_number
For me it's:
$ ~/./scripts/ngrok http 3000
After that do these 3 things for adding your work station to QuickSight whitelist:
In the terminal with ngrok copy generated domain which starts with
the https (i'll name it ngrok_domain), NOT WITH HTTP. For
example: https://047956358355.ngrok.io
Go to the Underwater rocks p.2 and add ngrok_domain
Open your browser and go to the path with iframe, but use ngrok_domain instead of localhost:3000. For example, your embedded dashboard path is localhost:3000/embed_dashboard. Change it to https://047956358355.ngrok.io/embed_dashboard
After all these steps all is start working for me. I'm sure that some of the points here are superfluous, but i'm really tired of working with this integration, so here you yourself decide what should be left and what should be removed.
I hope my answer helped at least someone

Unable to update Table Row Values

I am attempting to update a table using a python library to iterate through the table rows.
I get this error: "Error Message: The API you are trying to use could not be found. It may be available in a newer version of Excel."
Adding rows succeeds, but any APIs on the rows endpoint doesn't work, I can't get range or update a row. I even tried going directly to requests to have more control over what gets passed. I tried both the v1.0 and beta endpoints as well.
https://learn.microsoft.com/en-us/graph/api/tablerow-update?view=graph-rest-1.0&tabs=http
Here is the URL Endpoint I am calling:
https://{redacted}/items/{file_id}/workbook/tables/Table1/rows/0
Any help is appreciated.
Update to add code (you have to have an existing authenticated requests session to run it in python):
data = {'values': [5, 6, 7]}
kwargs = {
'data': json.dumps(data),
'headers': {
'workbook-session-id': workbook.session.session_id,
'Content-type': 'application/json'}}
# Works
sharepoint = 'onevmw.sharepoint.com,***REDACTED***'
drive = '***REDACTED***'
item = '****REDACTED***'
base_url = f'https://graph.microsoft.com/v1.0//sites/{sharepoint}/drives/{drive}/items/{item}'
get_url = f"{base_url}/workbook/tables/{test_table.name}/rows"
session = office_connection.account.connection.get_session(load_token=True)
get_response: requests.Response = session.request(method='get', url=get_url)
print(get_response.text)
# Doesn't work
url = f"{base_url}/workbook/tables/{test_table.name}/rows/1"
response: requests.Response = session.request(method='patch', url=url, **kwargs)
print(response.text)
That's an issue. Unfortunately it not documented at the moment in the offical documentation.
I could make it work by changing the url from ".../rows/1" as ".../rows/itemAt(index=1)"
Posting the C# solution for others since the Msft Docs are incorrect and the actual solution is similar to #Amandeep's answer for javascript.
The docs (incorrectly) say:
...Tables["table_name"].Rows["row_num"].Request().UpdateAsync(); // incorrect!
Correct way:
...Tables["table_name"].Rows.ItemAt(123).Request().PatchAsync(wbRow); // correct!
Note the .ItemAt method takes an int, not a string.

Put_connections to create a new event with Koala?

I'm trying to create a new event using the Koala gem and it's returning with the same error I got when I tried to update an event with an incorrectly formatted datetime value.
I can update just fine now but still cannot create an event.
Here's the code I use on my update method which works:
start_time = safe_params[:start_time].in_time_zone
end_time = safe_params[:end_time].in_time_zone
graph.put_connections(safe_params[:fb_id], "event", {
name: safe_params[:name],
description: safe_params[:description],
privacy: safe_params[:privacy]
})
And here's the code I'm trying to use to create a new event object:
graph.put_connections("/me/events", "event", { #this is the line that errors
name: safe_params[:name],
description: safe_params[:description],
privacy: safe_params[:privacy]
})
According to Facebook's documentation on creating an event (https://developers.facebook.com/docs/graph-api/reference/user/events/), I should be able to create a new event just by initiating a post to /me/events. Anyone have any idea?
I also tried:
graph.put_connections("/"+current_user.fb_id.to_s+"/events", "event", {
Thanks!
What happens if you do something like this?
graph.put_connections("me", "events", {
name: safe_params[:name],
description: safe_params[:description],
privacy: safe_params[:privacy],
start_time: ...,
end_time: ...
})
So after messing with Facebook's Graph Explorer and attempting hundreds of different combinations with put_connections I decided to make a straight graph_call using Koala.
Finally got an ID response back. I almost cried. Thought I'd share with the community in case there's someone else trying to do the same thing.
event_response = graph.graph_call("/me/events",{
name:safe_params[:name],
start_time: safe_params[:start_time],
privacy_type: safe_params[:privacy],
access_token: current_user.oauth_token}, "POST")
safe_params[:fb_id] << event_response["id"]
#event = Event.create safe_params
I make the call in a stored variable event_response because the Facebook Id returned is used in my app.
First thing I found out: despite using "privacy" as the name of the privacy field when GETting from Facebook and saying so in their documentation, "privacy_type" is actually what you want (found this out in another SO post).
The second thing I found out is even though you are authenticated (have a user token) when you make a graph_call you STILL need to pass along the current_user access token along with making a POST graph_call.
Hope this helps someone!

Tracking JSON calls with Google Analytics in a Ruby/Rails app

I searched a lot about this issue but I can't find anything good. I think that this is a common problem: you have a web app and build JSON APIs on top of your platform, so you can develop some widgets, mobile apps or third party applications.
I know that there a are a lot of specific analytics services via API (like Mixpanel, Kissmetrics and many others) but I want to track all the JSON calls also via Google Analytics.
I found that the best method is to use the __utm.gif image but strangely I cannot find any plugin or gem to use this image.
So I tried to build my own method without success (see the code below)...
Someone can help?
def google_analytics_call(page_title)
today = Time.now.to_i
utma = cookies[:__utma].to_s
utmb = cookies[:__utmb].to_s
utmc = cookies[:__utmc].to_s
utmz = cookies[:__utmz].to_s
utma = (rand(8).to_s + "." + rand(10).to_s + "." + today.to_s + "." + today.to_s+ "." + today.to_s) unless cookies[:__utma]
utmb = rand(8).to_s unless cookies[:__utmb]
utmc = rand(8).to_s unless cookies[:__utmc]
utmz = rand(8).to_s+ "." + today + ".2.2.utmccn%3D(direct)%7Cutmcsr%3D(direct)%7Cutmcmd%3D(none)" unless cookies[:__utmz]
Thread.new do
params = {
:utmac => GOOGLE_ANALYTICS,
:utmcc => "__utma%3D"+utma+"%3B%2B"+"__utmb%3D"+utmb+"%3B%2B"+"__utmc%3D"+utmc+"%3B%2B"+"__utmz%3D"+utmz+"%3B%2B",
:utmcn => "1",
:utmcs => "-",
:utmdt => page_title, #page title
:utmhn => BASE_URL,
:utmwv => 1,
:utmt => "page",
:utmr => request.referer
}
puts params
http_get("www.google-analytics.com", "/__utm.gif", params)
end
end
i think you want to use the async tracker, which is part of google analytics. Here is an example of how I track clicks that fire an async AJAX event:
$('.trackable').bind('click', function(event){
var action = $(this).attr('action');
var category = $(this).attr('category');
_gaq.push(['_trackEvent', action, category]);
});
The "_gaq" is the google asynchronous queue and can be added to any JS function you want to track metrics within. The function above allows you to add a class called "trackable" and track events when the user clicks on it. An example looks like this:
<a category='FEATURED' action='Like This' class='trackable' href="http://MYSSERVER.com/foo.json" target='_blank'>track asynchronously.</a>
Not quick answer, but I think you should try Gabba gem

Resources