getUser() Method on ApiAssistant - actions-on-google

I'm trying to get the User_id from a request. Currently I am just using API.AI to build the skill before wiring in the actual Google Home API. When I use the following snippet, I get
"TypeError: Cannot read property 'data' of null
at Assistant.ApiAiAssistant.getUser"
const assistant = new ApiAiAssistant({request: request, response: response});
let userId = assistant.getUser().user_id;
Am I just unable to use the getUser() method when testing directly with API.AI? Do I need to fully deploy and test with the Home Simulator in order to make a call to getUser() without causing an error?
Thanks!

Related

Can I search a specific webpage in google action console?

I am trying to create a google action for the assistant to receive a name from the user and search for it on a specific website https://www.findyello.com/barbados/white-pages/?search=$person_name
I am currently unable to use the SDK and as a result, am using the Google Actions Console. Is there a way to do this solely using the Action Console?
If you want to make external API calls, you will need to have an intent that captures the search query and use a webhook to make an external API call, process the result, and return it to the user.
The code for the webhook would look similar to this:
app.handle('search', async conv => {
const query = conv.intent.params.['param_name'].original
const res = await fetch(`https://www.findyello.com/barbados/white-pages/?search=${query}`)
// Parse res into text
conv.add(`Here is your first result. ${text}`)
})

Facebook OAuth LoginInfo is null on callback

I am building a test application and testing out externallogins via facebook.
I am using fiddler and when I click the button to login via facebook I am getting code 200 results (but they are locked due to HTTPS), but I am receiving a null value for loginInfo.
Here specifically:
[AllowAnonymous]
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); // this is null
if (loginInfo == null)
{
return RedirectToAction("Login");
}
I have reset my secret key and that does not work. I have the most updated version of Microsoft.AspNet.Identity.Owin (2.2.1).
What is the deal with this?
Any help is appreciated.
Assuming you created a new Facebook App as well, it'll work on the latest Facebook Api versions. Default templates don't seem to work out of the box anymore, due to Facebook's changing Api. They've reduced the number of fields that are returned by default and all additional fields now have to be specifically asked for.
Have a look at the following post, which contain 2 possible workarounds for this.
Why new fb api 2.4 returns null email on MVC 5 with Identity and oauth 2?

400 Bad Request when implementing custom friend selector

I'm trying to implement a custom multiple friend selector to invite users to my game. I get the list of users calling the Graph API call InvitableFriends, and create a UI for it.
After the user selects the corresponding users, I get all the invitation tokens of the users, and make a call to an App Request as follows:
public void InviteFriends(string message, string title, FacebookDelegate callback, string[] to = null, string data = "")
{
if (FB.IsLoggedIn)
{
FB.AppRequest (message,
to,
"",
null,
null,
data,
title,
callback);
}
}
But when the call is made, I'm getting the following error:
400 Bad Request
UnityEngine.Debug:LogError(Object)
FbDebug:Error(String)
Facebook.FallbackData:JSFallback(String)
Facebook.AsyncRequestDialogPost:CallbackWithErrorHandling(FBResult)
Facebook.<Start>c__Iterator0:MoveNext()
My callback function is never called, so I can't see what the error is.
I'm using Unity 4.3 & Facebook SDK 5.1
Thanks for your help!
EDIT: I'm pretty confident that the issue is that in the TO parameter I'm passing the invite tokens that the Invitable Graph call is giving me, AND NOT THE Ids.
I tested the InteractiveConsole.cs example of friendsmash with the invitable token and it also failed. How can I get the ids of the invitable friends?
just check the url request. It may be some thing wrong with it.
or
go to https://developers.facebook.com/apps/{app-id}/app-details/
in "app Info" section, choose the proper category and sub category.
I had a similar issue.. Figured out that FB.init() has to be called before using the invitable api. Without it you would get a "400 Bad Request"
I was keeping the old access token in playerprefs and just checking it again for validity and not actually initialising FB to save load time. But eventually I had to do FB.init()

Check if facebook user is authenticated

I am building a helper class that would allow me to manage facebook account in a windows form application. I am using Facebook C# SDK. As it is suggested in its documentation, to know if the user is authenticated one would get the loginUrl
var loginUrl = oauth.GetLoginUrl(parameters);
and then afterward, navigate to that Url
webBrowser.Navigate(loginUrl);
Since I am on the back end of the application, I wonder how one can write a helper class that will return true or false to show if the user is authenticated or not. I would love to do something like:
public static bool IsUserAunthenticated (string appId, string[] extendedPermissions)
How can this function be written? Any ideas? Remember I am using windows form on .net 4.0
assuming this function is called some time after
webBrowser.Navigate(loginURL)
A solution like this could work:
assuming:
The user has already authorized your application
'facebookClient' is a static class field is already initialized
public static bool isUserAuthenticated() {
try
{
facebookClient.Get("/me");
//the lack of an exception thrown is a sign of success
return true;
}
catch (FacebookOAuthException e)
{
//your access token used to initialize 'facebookClient' is invalid
return false;
} }
Some general notes:
you didn't show any code to handle the retrieval of the actual access
token. I've been assuming you left that out for brevity.
passing in 'appID' and 'extendedPermissions' means that this method
would be used to REGISTER the user, not for testing to see if they
were already a user of your application.
related to the above point, you could pass in the access token as an
argument so you would be able to initialize 'facebookClient' inside
the method and run the authentication test.
To sum that last little bit up, if you're not already aware, you need to realize there are two distinct stages: getting the access token and using the access token.

Access token error when trying to post a Facebook score in a canvas application

I'm trying to integrate the scoring system in my canvas app with Facebook's, implemented using MVC 3 and the 5.2.1.0 Facebook SDK.
A simplified hello-world variant of my game controller looks like:
public class MyController : Controller
{
[CanvasAuthorize("publish_action" /*And some others*/)]
public ActionResult Index()
{
var fb = new FacebookWebClient();
var scores = fb.Get("/me/scores"); // Works (I think)
fb.Post("/me/scores", new { score = 10 }); // Throws an exception
}
}
The call to get scores looks like it's giving me something sensible; the call to write a score value throws "(OAuthException) (#15) This method must be called with an app access_token."
What've I missed? The application id and secret are correctly set in my web.config - for example, I can successfully post an application apprequest in other parts of the actual application not shown in this stripped down test copy. Rummaging around with the debugger shows me that the FacebookWebClient object contains a non-empty access token field, and that that's included in the URI that fb.Post eventually uses.
The Facebook scores page (that Björn links to) mentions only publish_actions but I've tried including other pertinent sounding permissions, such as offline_access and user_games_activity to no effect.
I am assuming that the CanvasAuthorize attribute does the login correctly - it certainly seems to let me send an application apprequest, so it looks as if it's doing the right thing...
Your app needs the permission to write to the users profile. You can use the Graph API to request the required permissions from the user. If granted, Facebook will give you the required access token that you can then use in your request to Facebook. This practice ensures that you only perform actions, the user allowed you to.
Edit_: After looking at the docs: Are you sure you have the required permissions from the user like described here http://developers.facebook.com/docs/score/ ?
Please see this link. You'll need to get an facebook app. Using the apiId and SecretId, you can then post using the information in the link below. The key is adding &scope=manage_pages,offline_access,publish_stream to the url.
like so:
"https://graph.facebook.com/oauth/access_token?client_id={0}&client_secret={1}&grant_type=client_credentials&scope=manage_pages,offline_access,publish_stream";