How to get SessionId - actions-on-google

I'm trying to create an userEntity based on Dialogflow's reference but I could'nt find how to get the SessionId that is expected as parameter, can someone that had done this before cast some light on the subject for me? All answers related to Dialogflow that I've managed to find were regarding to V1 and looks like it changed a lot on V2.

The userEntity has been replaced with a session entity under V2. As you note, you need to use the sessionID as part of the name of this Entity.
Since you'll be doing this as part of the fulfillment, you can get this as part of the parameters that Dialogflow sends your webhook as part of the top-level attribute session in the JSON sent to you. If you're using the dialogflow-fulfillment library, this should be under agent.session.

Related

How to pass user id

Suppose super admin wants to see another sub admin's details
my current method is GET -- domain/api/user/get_by_id/{id}
I'm using JWT also.
is my method correct?? Is there any other method where I don't put the id directly in URL
my current method is GET -- domain/api/user/get_by_id/{id}
So, answering your questions one by one,
is my method correct??
If you are using RESt Web services as you have added that tag, then no, this should not be the url. I would suggest you to read upon REST web services a little as the url should look somewhat like this.
GET -- domain/api/user/{id}
Also the id you put in url is a public one and not the one of your database. So a entry in the database should look like:
Id | Username | userId (it is public)
1 | debabrata| r1398fh9238yhas89
So to call the url r1398fh9238yhas89 will be passed and not 1.
Is there any other method where I don't put the id directly in URL
You could encode the id in base64, jwt style or some kind of other encryption or as earlier stated just send a public ID which doesn't mean anything for your database.

REST API User Resource and its Password

I'm still learning REST API principles and this one still confuses me. Password inside User Resource is private and of course cannot be placed in a response, while sometimes we need to get user data for public (e.g. when someone seeing someone else's user page). How do we handle this based on REST API principles? Should I remove password inside response before sending it?
Yes, you should not return the password in response. I would suggest you should create two DTOs
UserInputDTO: This contains the password and other values
UserOutputDTO: Here you have only those fields which are useful for the output and we can exclude password field and fields related to your internal implementation.
If your input and output looks same then you can add JsonIgnore annotation on the password field.
If by removing you meant setting it null then still the user can see the fieldname password, and if at any time you forgot to set it null then it will be a security issue. To solve this issue, you can use the JsonIgnore annotation.

Extracting raw message in Gmail apps-script

In my Gmail-addon, I want to be able to read the raw (MIME) message of the current email.
How can I do that?
You can retrieve the message ID of the current message using e.messageMetadata.messageId at function buildAddOn(e){}. I cannot uderstand about raw (MIME) message in your question. So I propose 2 patterns.
If you want the raw data of Byte[], you can retrieve it from message ID using Gmail.Users.Messages.get() of Advanced Google Services as follows.
Gmail.Users.Messages.get("me", messageId, {format: "RAW"}).raw
If you use this, please enable Gmail App at Advanced Google Services and API console.
If you want the raw data of String, you can retrieve it from message ID using GmailApp.getMessageById() as follows.
GmailApp.getMessageById(messageId).getRawContent()
Note :
If you use this, please set "https://www.googleapis.com/auth/gmail.addons.execute", "https://mail.google.com/" to the scopes.
If other scopes are required to be added, please also add them.
References :
Gmail Add-on
Gmail.Users.Messages.get()
getMessageById(id)
If I misunderstand your question, I'm sorry.

Linkedin API get public-profile

I am trying to get the id from the public-profile-url. The query looks like:
https://api.linkedin.com/v1/people/url={https://www.linkedin.com/in/name}
However, what I get get back from linkedin is:
<error>
<status>400</status>
<timestamp>1460131755319</timestamp>
<request-id>2OV9FJ0DTR</request-id>
<error-code>0</error-code>
<message>[invalid.param.url]. Public profile URL is not correct,
{url=}; should be {https://www.linkedin.com/pub/[member-name/]x/y/z} or
{https://www.linkedin.com/in/string}</message>
The interesting part is:
Public profile URL is not correct, {url=}; should be {https://www.linkedin.com/pub/[member-name/]x/y/z} or {https://www.linkedin.com/in/string}
The url clearly adheres to the rules that they mention and the url works. Any idea on how to fix it?
You cannot reliably retrieve a member ID from a profile URL. id values that you can rely on are returned as part of Profile API calls. From time to time, LinkedIn changes the format of it's public profile URLs, so attempting to parse them or reconstruct them can leave your app in a broken state. The public-profile-url field should be considered read-only, and not something you try and parse or create yourself.
e.g.: GET https://api.linkedin.com/v1/people/~:(id,first-name,last-name,public-profile-url)?format=json
id values are encoded to specific LinkedIn applications and cannot be re-used between apps. As a result, any value you attempt to pull out of a URL won't be of any use to you. The information needs to be acquired via an API call.

Twitter API : Decode string returned by getFollowerIDsFor from Twitter (MGTwitterEngine for Obj-C)

New Question
Thank you for your reply Arcain. I guess question got mis-represented. I apologize for that.
My interpretation was like getFollowerIDsFor method as name suggests should be getting list of follower IDs, but it is not so.
My actual question is, how to use MGTwitterEngine API to get list of follower/following persons from Twitter. Though I went through documentation was not able to find out the same.
Regards,
Jennis
Previous Question
We can get list of Follower using getFollowerIDsFor through MGTwitterEngine object. It always returns some string which is not understandable for me i.e. how to decode or something like that ?
let say resultant string is "025815FA-BAF6-49E6-96B4-86F2D4C8C6CA"
how to understand what is there in this string ? can anyone highlight on this please ?
Help would be appreciated.
Regards,
Jennis
That value is a unique identifier and doesn't really mean anything. I'm not familiar with Cocoa, but when I looked around I found the following in the README file for MGTwitterEngine, and it seems relevant to what you're asking:
A note about the data returned from Twitter
Each Twitter API method returns an NSString which is a unique
identifier for that connection.
Those identifiers are passed to all
the delegate methods, so you can
keep track of what's happening.
Whenever a request is successful, you will receive a call to your
implementation of requestSucceeded: so
you'll know that everything went OK.
For most of the API methods, you will
then receive a call to the appropriate
method for the type of data you
requested (statusesReceived:... or
directMessagesReceived:... or
userInfoReceived:...). The values sent
to these methods are all NSArrays
containing an NSDictionary for each
status or user or direct message, with
sub-dictionaries if necessary (for
example, the timeline methods usually
return statuses, each of which has a
sub-dictionary giving information
about the user who posted that
status).
Just try calling some of the methods and use NSLog() to see what data you
get back; you should find the format
very easy to integrate into your
applications.
Sometimes, of course, requests will fail - that's just how life is. In the
unlikely event that the initial
connection for a request can't be
made, you will simply get nil back
instead of a connection identifier,
and then receive no further calls
relating to that request. If you get
nil back instead of an NSString, the
connection has failed entirely. That's
a good time to check that the computer
is connected to the internet, and so
on.
It's far more common however that the connection itself will go ahead just
fine, but there will be an error on
Twitter's side, either due to
technical difficulties, or because
there was something wrong with your
request (e.g. you entered the wrong
username and password, or you tried to
get info on a user that doesn't exist,
or some such thing). The specific
error conditions are mostly documented
in the Twitter API documentation
online.
In these cases you'll receive a call to requestFailed:withError: which will
include an NSError object detailing
the error. Twitter usually returns
meaningful HTTP error codes (like 404
for 'user not found', etc), and in
that case the -domain of the NSError
will be "HTTP" and the -code will be
the relevant HTTP status code. The
userInfo of the NSError will contain a
key "body" that may contain the
response body and "response" which
will contain the NSHTTPURLResponse.
This makes it really, really easy to
know what's happening with your
connections.