I am working on a small module which needs to automatically post links on a Facebook page. I have done the following setup:
In order to obtain a valid access token (manually for now - I know it is not recommended, but it does the job in my case) I have done the following:
From the json which I get after step 4 I copy the access token of the page which I am interested in and post the link with the following C# code:
try
{
dynamic data = new ExpandoObject();
var fbm = message as FacebookMessage;
data.access_token = ConnectionData.AuthenticationToken;
data.message = fbm.Message;
data.link = fbm.Link;
data.name = fbm.Name;
data.caption = fbm.Caption;
data.description = fbm.Description;
if (!String.IsNullOrEmpty(fbm.Icon))
{
data.picture = fbm.Icon;
}
var @params = ((ExpandoObject)data).ToUrl();
var _currentRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(String.Format("https://graph.facebook.com/{0}/feed?{1}", _currentEndpoint.ObjectID, @params));
_currentRequest.Method = "POST";
_currentRequest.ContentType = "application/json; charset=utf-8";
_currentRequest.UserAgent = "Mozilla/4.0 (compatible; Windows NT)";
_currentRequest.Accept = "*/*";
_currentRequest.CookieContainer = new CookieContainer();
_currentRequest.KeepAlive = false;
//_currentRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
//using (var sw = new StreamWriter(_currentRequest.GetRequestStream(), Encoding.UTF8))
//{
// sw.Write(json);
//}
string json;
var resp = _currentRequest.GetResponse();
using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
{
json = sr.ReadToEnd();
}
var jsonSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var output = jsonSerializer.Deserialize<dynamic>(json);
return new OperationStatus();
}
catch (Exception ex)
{
return new OperationStatus { Exception = ex };
}
}
The "_currentEndpoint.ObjectID" is the Object ID of the page. The POST is done successful, and I see the link being posted both on my administrator's wall as well as on the Page itself as long as I am logged in as admin. The sooner I log out, I can't see any posted links nor anyone else who liked the page.
What gives? How can I make the links to show up on the page wall and also on the walls of the people who liked the page. I did check spam on the page, and I don't see my links there, and from the privacy settings everything seems visible.
After reading this post: Posting a link to a page not showing up? I finally got it up and running. The problem seem to have been with the access token, but I still haven't figured out what went wrong: Here is what I did in the end:
That seem to have provided me the access token I needed to post visible links to everyone on the page wall.