I'm trying to post directly to an application's wall without linking it to my account. I keep getting a "(OAuthException) (#200) The user has not granted the application the permission to automatically publish feed stories". This is from a winform application.
var oAuthClient = new FacebookOAuthClient();
oAuthClient.AppId = "APP_ID";
oAuthClient.AppSecret = "APP_SECRET";
dynamic token = oAuthClient.GetApplicationAccessToken();
var appToken = token.access_token;
FacebookClient fbClient = new FacebookClient(appToken.ToString());
var args = new Dictionary<string, object>();
args["message"] = "Testing 123456789 from C#";
fbClient.Post("/APP_ID/feed", args);
Citing from facebook docs for stream.publish:
Posting to Your Application's Profile Page
In order to use stream.publish to post on the Wall of your application profile page (your application's About Page), all the following conditions must be true:
The posting user needs to grant the application the publish_stream extended permission.
The posting user must like the application's profile page.
A developer of the application must edit the application profile page's Wall Settings (Edit Application > Edit) and verify under Posting Ability that Fans can write or post content on the wall is checked.
From this it is obvious you cannot post to application wall with application token, only with token of user that likes the app.
Related
My problem is: When I post to page's wall some message with link it shows as Posted By Others, without link it shows normally in page timeline (Im group's admin ).
The same code posts to my timeline just fine:
I use AS3 library.
My permissions:
"publish_stream", "user_photos","publish_actions","manage_pages"
my post code:
var params:Object = new Object();
params.message = messageTextInput.text;
params.description = "description";
params.caption = "caption";
params.name = "name";
params.link = "http://www.ya.ru";
params.picture = "http://image.bayimg.com/cajchaado.jpg";
FacebookDesktop.api(page.id+"/feed", onCallApi, params, "POST"); //use POST to send data (as per Facebook documentation)
Facebook documentation says I can post either link or message, but it works just fine, except of showing in "Recent posts by others" ( please see attached screenshot ).
To post on a fanpage on behalf of itself (not the user), you have to use the page access token.
What happening is- when you make the call, the sdk uses the default token (user token), so the post is published on behalf of the user which is displayed in the "Recent Post by Others" section in the page.
Since you have requested for manage_pages already in your code, you can simply obtain the page access token with this call- /{page-id}?fields=access_token. Use this token with your current call just by adding the parameter access_token-
....
params.picture = "http://image.bayimg.com/cajchaado.jpg";
params.access_token = "{page-access-token}";
....
I'm currently building a website where I'll offer the users a link to share a photo on Facebook, whereby the application would:
Provide the user with a link to request permissions from Facebook
Redirect back to the website with the access code from the user's acceptance of the permissions
Server-side post the photo to the user's photos
To generate the link for the first step, I'm doing this:
var fb = new FacebookClient();
var options = new
{
client_id = "MY_APP_ID",
client_secret = "MY_APP_SECRET",
redirect_uri = string.Format("http://localhost:51182/Home/FacebookShare?path={0}", Server.UrlEncode(path)),
response_type = "code",
scope = "publish_stream"
};
var loginUrl = fb.GetLoginUrl(options);
Then this loginUrl value is added to my MVC ViewModel and used in a link in the View.
However, I've noticed that the loginUrl contains the client_secret value in clear text. Isn't this a bad thing? Shouldn't users not be able to see the client_secret? Did I go about this the wrong way?
The fb.GetLoginUrl method is rather simple, in that it just adds anything you give it inside the options object as parameters to the URL created.
So take
client_secret = "MY_APP_SECRET",
out of your options object, and it should not show up in the login URL any more.
I am using RESTFb api to post a message on facebook wall
my code is:
val facebookClient: FacebookClient = new DefaultFacebookClient("access_key")
def publishMessage(msg:Mesage): String = {
val publishMessageResponse: FacebookType = facebookClient.publish("me/feed", classOf[FacebookType],
Parameter.`with`("message", msg))
publishMessageResponse.getId()
}
But this code is working only when I am login in my facebook account.If I am not login it give me the error of "user session logout". and it told me to generate the access token every time.
Thats because you are trying to post to your own Wall.. thats why, OAuth needs to validate you are logged otherwise it wont post anything... if you where posting to a PAGE... well that's diferent you could use APP and SECRET ID's to generate AccessTokens on your website.
I created a Facebook app that I will use to programatically post information to Facebook. I've got it working so that I can post to my wall, but not the page I'd like it to go to (for which I am 1 of 2 administrators).
this posts to my page just fine:
FacebookClient facebookClient = new DefaultFacebookClient("<ACCESS_TOKEN>");
FacebookType publishMessageResponse = facebookClient.publish("<MY_FB_NAME>/feed", FacebookType.class, Parameter.with("message", "Testing..."));
but if I try to post the page, I get an error:
com.restfb.exception.FacebookOAuthException: Received Facebook error response of type OAuthException: (#200) The user hasn't authorized the application to perform this action
The code is the same, except I replace my name with the page's ID:
FacebookClient facebookClient = new DefaultFacebookClient("<ACCESS_TOKEN>");
FacebookType publishMessageResponse = facebookClient.publish("<THE_PAGE_ID>/feed", FacebookType.class, Parameter.with("message", "Testing..."));
The app is listed as one of the apps for the page.
Thanks for any help with this,
Frank
Are you sure you have the correct (publish_stream) Permission?
You'll need that to post as the user to places other than their own profile.
As FaceBook launched a new concept of pages, I created a page, but I am not able to find any C# SDK for posting on that page's timeline from code.
First you need C# SDK
you can download from here
http://csharpsdk.org/
may be you need manage_page permission to get a page access token
you can get a page access token using this Graph Request http://developers.facebook.com/tools/explorer/?method=GET&path=me%2Faccounts
after getting page access token you can post a on page wall using this code
var fb = new Facebook.FacebookClient(PageAccessToken);
var postArgs = new Dictionary<string, string>();
postArgs["link"] = "http://www.foo.com";
postArgs["name"] = "Click Here To View";
postArgs["message"] = Message;
fb.Post("[pageid]/feed/", postArgs);