Post on facebook SDK WP8 - facebook

(OAuthException - #200) (#200) The user hasn't authorized the application to perform this action when post on facebook by through winows phone 8 code:
dynamic fbPostTaskResult = await instance.PostTaskAsync("me/feed", postParams);
permessions add in session = await App.FacebookSessionClient.LoginAsync("user_about_me,read_stream,publish_actions");
Debug access token on facebook app display
App ID -- User ID -- Issued 1409307661 Expires 1414491661 Valid True Origin Mobile Web Faceweb Scopes : public_profile

Did you try adding the Permission called status_update?
Perfect sample would be this:
why does posting to facebook page yield "user hasn't authorized the application"
Which Facebook permissions allow for posting to a page wall (not profile wall)?

Related

I can post links in a page feed but not just a message

I'm trying to post to a facebook page (as the page and as the admin user with each one access token) with just a parameter 'message'.
I've the same error in php and in Graph API Explorer in both cases:
{
"error": {
"message": "(#1) An unknown error occurred",
"type": "OAuthException",
"code": 1,
"error_data": {
"kError": 1455002
}
}
}
The same post to the API adding a paremeter link or just link without message works fine.
The user has granted those permissions: create_note, email, manage_pages, photo_upload, publish_actions, publish_stream, share_item, status_update, user_friends, video_upload.
The app is in Sandbox Mode and the user is a test user, not a real one.
I'm able to write to user feed and to create custom actions for him.
I've verified both, the page access token and the user access token with Access Token Debugger.
I've already reviewed a lot of questions in stackoverflow, tutorials and blog posts.
What am I missing?
UPDATED: I can't either post a link in page with app access token.

API Error Code 191 using feed dialog with display=iframe

I am attempting to use the Facebook feed dialog within an IFRAME, but when viewing the webpage, it is displaying:
API Error Code: 191
API Error Description: The specified URL is not owned by the application
Error Message: redirect_uri is not owned by the application.
I have found similar posts, but still cannot find a solution after many hours of research.
Javascript code snippet to set IFRAME src:
FB.Event.subscribe('auth.authResponseChange', function (response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
// TODO: Handle the access token
if (accessToken) {
document.getElementById('fbIframe').src = 'https:// www.facebook.com/dialog/feed? display=iframe &app_id=OMITTED_APP_ID &access_token=accessToken &redirect_uri=http://asp.mydomain.com:8240/socialshare/ &show_error=true';
}
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
And for my application's setting on Facebook:
[BASIC]
App Domains: asp.mydomain.com
Select how your app integrates with Facebook: "Website with Facebook Login" (Site URL: http://asp.mydomain.com:8240/socialshare/)
[PERMISSIONS]
User & Friend Permissions: publish_actions
Extended Permissions: publish_stream
[ADVANCED]
Authentication: "Web"
[1] Note that in the IFRAME src, the value of redirect_uri is http:// asp.mydomain.com:8240/ socialshare/ - Could the difference in the port between asp.mydomain.com as the domain and asp.mydomain.com:8240 as the redirect_uri be the cause of the issue? If so, asp.mydomain.com:8240 is not allowed to be set as the App Domain in Facebook settings...
[2] Note the same error occurs when developing the web page locally on localhost:59700/ socialshare/ (using Visual Studio 2010)
[3] What exactly are the minimum fields required to successfully load the feed dialog in an IFRAME?
[4] I can successfully run and post a messgage using facebook feed dialog example documented here: https://developers.facebook.com/docs/reference/dialogs/feed/
[5] For the code snippet above and body of this post, I purposefully added spaces in the URLs in order for me to post this question.
Any help would be appreciated!
Thanks

How to post to a Facebook Page (how to get page access token + user access token)

I am trying to work out how to post to a Facebook page wall, when using my app as a different Facebook User (who is not the Page Administrator).
I get a range of error messages while testing:
Exception: 200: The user hasn't authorized the application to perform this action
The page administrator has visited the app and accepted the following permissions: publish_stream, manage_pages, offline_access
Here is the code I plan to use:
// Insert Page Administrators ID here
// This user is not the same user that is currently logged in and using the app
// This user is the page administrator who has authorised:
// - manage_pages
// - offline_access
// - publish_stream
$user_id = '123456789';
// Insert Page ID here
$page_id = '123456789';
$accounts = $facebook->api('/'.$user_id.'/accounts');
foreach($accounts['data'] as $account)
{
if($account['id'] == $page_id)
{
$page_access_token = $account['access_token'];
echo "<p>Page Access Token: $page_access_token</p>";
}
}
// publish to the wall on your page
try
{
$result = $facebook->api(array( "uid" => $page_id,
"method" => "stream.publish",
"access_token" => $page_access_token,
"message" => $message, ));
}
catch (FacebookApiException $e)
{
error_log('FB Error: Could not post on Page Wall. Page ID: ' . $page_id);
error_log('FB Error Message: ' . $e);
}
Note: There may be PHP errors in the code above, as I just spliced it on the fly, but its not so much the PHP errors I need correcting, but more my logically understanding of how I am meant to go about this process.
PROBLEM:
I can't access the $user_id/accounts information without an active user access token for the Page Administrator.
The end result that I'm trying to achieve is:
1.) A normal FB user goes to the app and submits a form
2.) The app posts a message on a FB Page wall, which is not owned by the FB user, but has previously been authorized by the Page Administrator with the following permissions manage_pages, publish_stream and offline_access
Q1. Since the Page Administrator has accepted the appropriate permissions, why can't I just generate an active user access token, without the actual Page Administrator user logging into the website?
Q2. Is there a way I can get the equivalent of /$user_id/accounts for the Page Administrator user_id, when logged into Facebook as a different user (which is why I do not use /me/accounts)?
Q3. Please confirm that my understanding of needing the page access token to post to the page wall is correct (or do I need the user access_token for the Page Administrator - see Q1)?
Q4. Anyone have a handy resource on what each type of access_token can actually access?
If you need any more information, please let me know.
I've spent the last few days working on this and I'm stuck.
Thanks!
You can ask the page admin for manage_pages along with offline_access. I do this in my production app to be able to post scheduled postings onto the pages' walls.
Nope. Not possible. That's what asking permissions is all about. And why not everyone gets to administer everyone else's pages. Could you image if you could administer anyone's page without them granting you access?!?
To post to the page as the page, you need a page access token. To post to page's wall as a user, you need a user access token.
Yes, please see: https://developers.facebook.com/docs/reference/api/permissions and https://developers.facebook.com/docs/authentication/
If you have further questions about any one of these, please start a new question. It's not really fair to users of stackoverflow to be hit with 4 questions in one and then to be asked followup questions to each of those.
I have done in Django:
Step to get Page_access_token:
facebook_page_id=360729583957969
graph = GraphAPI(request.facebook.user.oauth_token.token)
page_access_token=graph.get(facebook_page_id+'?fields=access_token')
This way you can get Page access token.
You can check this thing on Fb GraphAPIexplorer:
http://developers.facebook.com/tools/explorer
GET URL: fb_page_id?fields=access_token
for example: 360729583957969?fields=access_token
that will give you page_access_token

Facebook account delink or deauthorize facebook app and check status of linking from facebook app

My website application having feature login with Facebook login. And for which my app is present on Facebook. Login with facebook is working fine.
But application have feature of linking and unlinking facebook account to Facebook app.
How to check FB account is linked with specific FB app or not?
And how to unlink FB account from specific FB app if linked (On that user's request )?
("Linked" means we select "Allow" to FB app on request)
With the new Graph there is a documented way to deauthorize (I've tested it in the Graph API explorer and it works). Send an HTTP Delete command to "me/permissions" with a valid access token. Not only will it invalidate the access token, but it also removes the app from the user's list of auth apps. This requires the user to authorize the app again (going thru the permissions screens) to use it. Happy coding!
Please note Facebook in the process of deprecating the REST API, and have adding equivalent support to the Graph API User object for "auth.revokeAuthorization" method.
//$this->facebook is facebook object
//$userid is of logged in user or can be written hardcoded.
For checking linked in or not by making api call.
$user_id = $this->facebook->getUser();
$result = $this->facebook->api(array(
'method' => 'fql.query',
'query' => "SELECT is_app_user FROM user WHERE uid=$user_id"
));
$is_installed = $result[0]['is_app_user'];
if($is_installed==1) {
echo 'Linked';
}
else {
echo 'Not Linked';
}
For delinking or deauthorization the user by making app call:
$user_id = $this->facebook->getUser();
$access_token=$this->facebook->getAccessToken();
$result = $this->facebook->api(array(
'method' => 'auth.revokeAuthorization',
'uid' =>$user_id,
'access_token'=>$access_token
));
This can easily achieved with simple FQL query:
SELECT uid FROM user WHERE uid = {USER_ID_HERE} AND is_app_user = true
This will return uid of user if he is connected with app and nothing otherwise
Make an API call to /{USER_ID}/permissions with your App access token and it will show if that user has authorised your app
You can also check with the user's access token if you have one.
The response type will be something like this:
{
"data": [
{
"installed": 1,
"bookmarked": 1
}
]
}
There'll be one entry there for each extended permission the user has granted your app and the installed line means they've installed your app
For a user who hasn't installed your app the response will be:
{
"data": [
]
}
You can also use FQL as Juicy Scripter suggests in another answer
Here's how to deauthorize your app using Facebook iOS SDK v4:
#import <FBSDKCoreKit/FBSDKCoreKit.h>
...
NSString *graphPath = [NSString stringWithFormat:#"/%#/permissions", [FBSDKAccessToken currentAccessToken].userID];
[[[FBSDKGraphRequest alloc] initWithGraphPath:graphPath parameters:nil HTTPMethod:#"DELETE"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if ( !error ) {
NSLog(#"Facebook unlinked");
}
}];
Through the Graph API, from the docs (thanks #DMCS):
You can de-authorize an application or revoke a specific extended
permissions on behalf of a user by issuing an HTTP DELETE request to
PROFILE_ID/permissions with a user access_token for that app.
The olds REST API offers you auth.revokeAuthorization. You can read more about that on the auth.revokeAuthorization docs.
Be aware that the REST API will be deprecated in the future, although Facebook doesn't specify when exactly.
I am not aware of any way to get a list of apps a given user is connected to, or see any reason Facebook would make that available. To see if a user is connected to your app, the other answers here should provide you with a couple of ideas.

Trying to post directly to an application's wall

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.