Facebook page picture publishing working or not? - javascript

Reading the documentation of how to publish the page picture of a facebook page here:
https://developers.facebook.com/docs/graph-api/reference/page/picture/
Is this POST endpoint working?
I am able to get the picture from the
GET /{page_id}/picture?redirect=0&height=200&type=normal&width=200
instead of
GET /platform/picture?redirect=0&height=200&type=normal&width=200
as it says in the docs (It consistently says /platform/ in all examples and ref.).
But whatever I have been trying when POST / Publishing to the endpoint:
POST /{page_id}/picture
with url as a field
I get:
{
"error": {
"message": "(#1) Could not fetch picture",
"type": "OAuthException",
"code": 1
}
}
I tried both through the JS api and through the Graph API Explorer, using the page access token, posting with the url field.
Is this broken in the facebook graph api or am I doing something wrong here?
Step by step:
on the developers.facebook.com/tools/explorer -> Get Access token, and added manage_pages as extended permission
then GET me/accounts to get the page access token for my page (503383593111939): all 6 permissions is there.
copied access_token from me/accounts for page 503383593111939 into the access token input field in the same graph explorer and changed to POST /503383593111939/picture?url=http%3A%2F%2Fwww.wcdouglas.com%2Fimg%2Flogo.png, tried to add the url as a field without urlencode aswell but with the same result

The same happened with me. The only thing was that there was a space character after the query. Removing it would give you the desired result.
Try this query:
GET /{page_id}/picture?redirect=0&height=200&type=normal&width=200
I've just removed the space character in the end.
For post to work, you will have to do something like this:
POST /{page_id}/picture?url=http://images.com/img.jpg
For this, you'll be needing access tokens. You'll get those from here and here.

Related

How to POST an issue stub on GitHub using the GitHub API using the logged in user, without authentification keys?

Users of my web application are expected to provide bug reports as a GitHub issue, with a pregenerated title and body.
This works perfectly fine using GET for small bodies:
const title = getLastErrorTitle();
const body = getAllTheLogMessages();
window.open(`https://github.com/theuser/therepo/issues/new?title=${encodeURIComponent(title)}&body=${encodeURIComponent(body)}`);
If the user is logged in, GitHub presents the user with a new issue with the title and body already filled out, perfect. If not, GitHub prompts the user to log in and it works the next time.
However, if the body is too large, the GET request fails because the URL becomes too long.
After consulting the manual I tried doing the same with POST but I get a 404 from GitHub with the following test request (jQuery for brevity):
$.ajax({
type: "POST",
url: "https://api.github.com/repos/theuser/therepo/issues",
data: data = {title: "Test", body: "Test Body"},
});
My suspicion is, that the GitHub API was not designed with my use case in mind, but that POST always requires authentication and creates the full issue in one go, without letting the user change it beforehand like it is possible with GET.
How can I transfer the functionality of the GET method over to the POST method? I just want GitHub to present the user, that is currently logged in inside the browser, with a prefilled issue, without needing a token.
You can't. Otherwise, it would be a major CSRF exploit.
However, you can use OAuth authentication that will allow your application to use some features : https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps/
Or simply, redirect the user to a new issue page (for exemple with a simple HTML link <a>) with some automatic content, using this pattern :
https://github.com/{theUser}/{theRepo}/issues/new?body={theContentYouWhant}&title={theTitleYouWhant}
Example : https://github.com/CristalTeam/php-api-wrapper/issues/new?body=Hi,%20this%20is%20the%20body%20you%20want&title=Hello,%20this%20is%20a%20prefill%20issue
What I would suggest here is to generate a personal_auth_token at gihub and pass this token in the headers under Authorization field.
To generate personal_auth_token, login to github.com, go to settings -> developers settings -> Personal access tokens and generate one.
Pass this token in headers under Auhtorization: token. So in your AJAX request, it could look something like this:
$.ajax({
url: *yourUrl*
...
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', *token*));
},
});
One thing to note here is each of the developers POSTing to the repo will be requiring to generate their access token and you can't push this token on to a public Github repository because of obvious security breach. If you accidentally do so, the token is revoked immediately and you'll be required to create a new one.

Unable to delete comment using Facebook Javascript SDK - use right access-token

I'm trying to delete a comment using a Graph API call.
https://graph.facebook.com/[comment-id]?access_token=[access-token]&method=delete
However, in terms of access-token, I'm not sure which one to use? I have used my App's "User Access Token", "Page Access Token" and "App Token". It doesn't work for any of these.
[PS, my app has all permissions, and I have even submitted it for review]
I just wanted to know if it was even possible to delete a comment which was not posted by the application? (Because I see that Delete is only allowed for page access tokens).
So, please do let me know if it is possible to delete a comment from a user's posts. And if so, which access_token to provide.
The docs list all the neccessary Access Tokens and permissions:
https://developers.facebook.com/docs/graph-api/reference/v2.10/comment#deleting
I tried it with a user profile, it does not seem to be possible to post comments or delete them - no matter if was created by the App or manually:
Publishing comments through the API is only available for page access
tokens
For Pages, you need to use a Page Tokens with the neccessary permissions according to the docs.
It looks to me that you're doing an HTTP GET call and just putting &method=delete at the end. That's not how it works
You should do an HTTP DELETE call. So instead of doing something like $.get(...), you should do $.ajax with type: 'DELETE'
Also, make sure your token has publish_actions permission

JS SDK - Posting to a page wall

I am using the JavaScript SDK. I have an application that has publishing permissions and after certain actions are taken a post will be made to the logged in users wall like so:
FB.getLoginStatus(function (response) {
//we are authorized
if (response.status == "connected") {
var name = "Post name";
var body = "Post body";
var caption = "The caption";
var description = "The description";
var link = "http://www.facebook.com/mypage";
FB.api('/me/feed', 'post', { message:body,caption:caption,link:link,name:name,description:description}, function (response) {
console.log(response);
});
}
});
What I would like to able to do is post to a specific Facebook Page after a post is successfully made to the users page. Is there a way to securely pre-authorize an application to do that? Is this possible with the JavaScript SDK, or at all? I did some looking around and havn't found a definite answer. I'm looking at the FB documentation but find it to be a bit spotty in places. Could anyone tell me if this is possible? Any help or advice would be very much appreciated, thanks much!
Edit: my mistake, I should have supplied more info. Here is what I am trying to do:
var body = "The body";
var caption = "The caption";
FB.api("mypageid/feed", "post", { message: body, caption: caption }, function (response) {
console.log(response);
});
I am getting the error "this api call requires a valid app_id" however my page id is valid. When I call FB.init() I am passing my app id and it works for the first post to the logged in users feed.
Edit:
I have made the change the Igy suggested. Now I am getting the error:""(#200) The user has not granted the application the permission to automatically publish feed stories""
Now, as I said I am trying to post to a Facebook page. I have logged into the account that owns the page and I have gone to the app and clicked allow for the following permissions:
email,user_photos,publish_stream
When I am logged in with the account that owns the page and check my status:
FB.getLoginStatus(function (response) {
console.log(response);
});
I get "connected". Am I doing this incorrectly? Do I have to do more than just authorize with the account that owns the page? Is there a way to set allow permissions for a page? I did a little digging but couldn't find an answer.
Edit :
Ok, now what is happening is IF I am logged into the account that owns the page the post will be made to the page. If I am logged in with another account I get an id back as a response to the API call but it doesn't seem to be a valid object id. For instance I just got this back:
id: 499973616681852_507724422573438
if I go to http://graph.facebook.com/499973616681852_507724422573438
I get an "unsupported get request" graph api exception, which suggest that id returned is not valid. I feel like I am close here but I am missing something. Any advice would be appreciated, thanks again to all who responded.
edit: removed the link to the page,that was left in unintentionally.
It's good practice to try getting it to work in the graph explorer first. Note that on the top right you can select which application to run under. I just made a post to your page using /PAGE_ID/feed and it worked fine. You'll need the publish_stream permission. If you can get it to work in the graph explorer you'll know it's possible to get it to work in the JS SDK and you've just made some sort of syntax error.
Also note there is an open high priority bug report on some calls to the graph returning "unsupported get request". So even though the id you are getting back is invalid, check the page itself to see if the posts are appearing.
I also noticed that the user itself is getting the same error. Try https://graph.facebook.com/507724422573438. Is this a test user for your app? Might be worth trying this as a real user if so.
Since you want to post to the page as the page itself, you'll need to authenticate as a page and then use that access token when making graph api calls. I am not sure if you'll be able to then use this access token for any user, or only users that are allowed to manage the page. It would be best for you to use the graph explorer to do some experiments to find out.

Facebook Page has a fan or not

Im trying to use javascript to determine if a user is a fan of a page that i've created on my account.
I found the facebook graph api which looks like just what i want. However it appears for some functionality i need an access token.
Here it says I can just http get my /user_id/accounts page with the manage_pages permission and it will list the access token for each page.
But when i submit https://graph.facebook.com/myuserid/accounts&scope=manage_pages i get "OAuthException : Access token is required to request this resource."
I also tried from this answer, but then i get "An error occurred, please try later".
Any suggestions most welcome.
You will need an access token to retrieve any information that is not public on facebook.
You can read up on this page about authenticating a user. Once your user is authenticated you can retrieve the access token and use it in your future requests (for that user)..
eg:
https://graph.facebook.com/{YOUR_USER_ID}/accounts&access_token={YOUR_ACCESS_TOKEN}

Facebook "Invalid redirect_uri", but the url looks fine to me

I'm getting the following error when trying to authenticate to Facebook with OAuth:
{
"error": {
"message": "Invalid redirect_uri: Given URL is not allowed by the Application configuration.",
"type": "OAuthException"
}
}
My url looks like this:
https://graph.facebook.com/oauth/authorize?client_id=283993944973616&redirect_uri=http://dennys-m.appspot.com/fb_login/&scope=publish_stream,email&display=popup
I know there are a lot of other posts with this problem, but I can't see what would make my url invalid. Any ideas why I'm getting this error?
Your redirect url: http://dennys-m.appspot.com/fb_login/ must match the canvas url in https://developers.facebook.com/apps/ configuration panel.
Fortunately, these days Facebook gives the error message Invalid redirect_uri: Given URL is not allowed by the Application configuration. About a year ago no such exception appeared, just strange results.
In my case there was no / at the end of mine redirect uri! No comments to fb..
You have to register your redirect URL at Facebook console
First go to Advanced tab inside Settings
There after scroll down to Valid OAuth redirect URIs
register your url there the moment you will save changes it will stop giving this exception
if you are using localhost:3000 as your call back url,
For example your call back uri may like: http://localhost:3000/sessions/create, where sessions/create are the controller and action respectively,
then make your Canvas URL as: http://localhost:3000/
Something else:
It might sound stupid but read those snippets carefully.
It took me several days to figure out why I always got this error message
Invalid redirect_uri URI is not supported
Those curley brackets are not a part of the URI!
Again, it might sound stupid and some of you out there might say "This would never happen to me" but if you are new into something use your brain ( I didn't ;) )

Categories