I'm trying to add Test Users to my Facebook app so I could better test the Request dialog and check if I could retrieve the tracking information. But I keep getting the error in the title of this question. Here's my code:
[CanvasAuthorize]
public ActionResult Add()
{
var fb = new FacebookWebClient(FacebookWebContext.Current);
dynamic result = fb.Post(string.Format("{0}/accounts/test-users", FacebookWebContext.Current.Settings.AppId),
new { installed = false});
return Content(result.ToString());
}
The weird thing is that while debugging, I've checked the Current context and it seems like everything is fine. All properties are there (including the App Secret) and nothing null. Why is that happening?
UPDATE: C# equivalent of file_get_contents (PHP)
I guess the error and the old naming is a bit misleading, what you need here is an application access token. And it's mentioned in the Test Users documentation:
You can create a test user associated
with a particular app using the Graph
API with your app access token.
For PHP users, I've written a tutorial on how to get this access token here.
You need a valid access token to include in your URI, such as "&access_token=APP_ACCESS_TOKEN". Try Facebook's Access Token Tool.
I noticed you didn't share your solution, it's important to share in case others have the same issue.
Here's how I programmatically get an App client:
var fbAppClient = FacebookWebClient(AppId, AppSecret);
While late to the party, I thought I'd add the actual fix to the original code since I was running into the exact same issue.
In Kassem's above code, on the 4th line, the following:
var fb = new FacebookWebClient(FacebookWebContext.Current);
is what was causing the error in the title for me. Replacing it with:
var fb = new FacebookWebClient(FacebookApplication.Current.AppId, FacebookApplication.Current.AppSecret);
Resolved the issue.