Facebook API - POST a comment on a private groups post - javascript

I have successfully retrieved an post made on an private group and the comments made on this post. I want also to make the users on my app to be able to reply to comments on that post but cant get my head around this problem.
This is the API URL to GET all the comments on an post ID.
1338804626636796_1351943298656262/comments
When i try to do a POST call to this URL i get as a result:
{ "error": {
"message": "(#3) Publishing comments through the API is only available for page access tokens",
"type": "OAuthException",
"code": 3,
"fbtrace_id": "AM6a-he8gLoFA8SDVHjfDYO"
}
}
As far as i understand Page Access Token is used to manage Pages... Im working with Groups not Pages, and when i try to create a Page Access Token my Group that i want to manage wont show up ofcourse.
I then follow this guide:
Get a page Access Token API Docs
It asks for a PAGE ID, i have group ID but i try it anyways and get this as a response:
code: 100 fbtrace_id: "AnzTkEAsbp8s-Z__QawDBYX" message: "(#100) Tried accessing nonexisting field (access_token) on node type (Group)" type: "OAuthException"

Related

How can I get comments when I have facebook post id

I want to fetch all comments of a post on facebook (my post and my friends post) using my access token.
I already have a post id, but when I call FB.api('/{post_id}/comments?access_token=xxxx), it returns error code 100 with the description:
Unsupported get request. Object with ID
'988927087866664_1344444165648286' does not exist, cannot be loaded
due to missing permissions, or does not support this operation. Please
read the Graph API documentation at
https://developers.facebook.com/docs/graph-api
Facebook also approved publish_actions permission for my website.
Thank you for your help

Can't correctly obtain OAuth to append to google sheet via Javascript http request

I can't for the life of me append to my google sheet via http request. More specifically I can't seem to get the Oauth formatting right. I don't want/need a uri or prompt for permission as its just me managing my own spreadsheet. First, I was trying with just my api key, but then found out that if you're editing data you need to obtain an access token. That's when I started trying to obtain the token through oauth2 following the TERRIBLE google api documentation. That's where I hit a wall and have just about given up. It's such a simple concept, I just want to add data to my spreadsheet on drive from an online script (housed on scriptr.io), but Google yet again makes things so unneccessarily complicated and don't help matters with their convoluted, misleading, and scattered documentation. Can someone please help me in accomplishing this? Here's where I'm at or what progress I've made thus far.
I've figured out how to correctly format the call to add a row of data to the spreadsheet.
POST https://sheets.googleapis.com/v4/spreadsheets/-/values/Raw%20Data!A1:D1:append?valueInputOption=USER_ENTERED
//Header
Authorization: Bearer {oauth_token}
//Payload
{"range": "Raw Data!A1:D1","majorDimension": "ROWS","values": [["Test", "$15", "2", "3/15/2016"]]}
I know the above works because I've successfully added the data using the OAuth 2.0 Playground. However, when trying it outside of the playground (on a rest client) I keep getting errors trying to obtain the token.
POST https://www.googleapis.com/oauth2/v4/token
scope=https://www.googleapis.com/auth/spreadsheets
client_id=------&
client_secret=-----&
refresh_token=-----&
grant_type=refresh_token&
access_type=offline
I use the client id & client secret from my api console and I use the refresh token I got by authorizing the spreadsheet api in the oauth playground, but the above POST request leads to the following error
Error 400
{
"error": "unsupported_grant_type",
"error_description": "Invalid grant_type: "
}
Can someone please help me figure out how to correctly do this?

How to comment in a closed group facebook api graph

I am developing on API Graph Facebook. I'm using JavaScript SDK. I want to comment in a group where I have published.
The problem is some groups are closed, although I am in these groups.
How can I comment in this groups?
For example, if I am in the explorer of Facebook developers I try to get a post mine, but when I execute the GET I obtain this error.
{
"error": {
"message": "Unsupported get request. Object with ID '114576608727103_527470874104339' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"fbtrace_id": "DVXM6hFnfeF"
}
}
I have same problem when I try to use POST method. I can comment in a groups open normal.
Note: I am in all groups that I want to comment.
Thank you.

Get newest post from a Facebook page as a string in JavaScript

I simply need to get the newest post from a specific Facebook page as a string in JavaScript for a website. I have never used the Facebook API and I'm still new to JavaScript, after many attempts I just can't figure out what the problem is...
So far this is everything I've done:
Created a Facebook app, chose 'website' for the platform
Inserted the JavaScript SDK code that I got from Facebook into my website code and replaced the placeholder 'appID' with the 'App ID' from my Facebook app
Became admin to the Facebook Page
On the Graph API Explorer page used the 'Get Token' dropdown to select 'Get Page Access Token', then selected the Facebook Page that shows up in the dropdown
Used the following request in the Graph API Explorer: 'https://www.facebook.com/pagenamehere/?fields=posts.limit(1)' (The output provides the post I need but with some extra information like "create_time", "id", etc. that I will most likely remove in JavaScript unless there is a more precise request I can use instead since I only need "message")
Copied the provided JavaScript code from 'Get Code' and inserted this under the JavaScript SDK code
replaced '//Insert your code here' with 'alert (response)', the alert message is: [object Object]
Either I don't know how to obtain "message" from '[object Object]', or I'm not getting the response I need. I've tried to do this with the webpage on a live server.
Please help, I'm out of ideas and I've read the Facebook API too many times.
Thanks in advance.
It's simple. Just have a look at the Graph API Explorer, and you'll get the idea how to access the message property:
Sample Graph API Explorer call
A call to /buzzfeed/feed?limit=1 will return
{
"data": [
{
"message": "science",
"created_time": "2015-11-23T07:01:00+0000",
"id": "21898300328_10154109572045329"
}
],
"paging": {
"previous": "https://graph.facebook.com/v2.5/21898300328/feed?limit=1&format=json&since=1448262060&access_token=&__paging_token=&__previous=1",
"next": "https://graph.facebook.com/v2.5/21898300328/feed?limit=1&format=json&access_token=&until=1448262060&__paging_token="
}
}
which means that
console.log(JSON.stringify(response.data.message));
should print you the message.
Thank you for your suggestions, they helped point me in the right direction and I was able to get this to work.
Here are the missing steps from my original post required to make it work:
Had to also add my domain to the 'Valid OAuth redirect URIs' field in 'My Apps' -> 'Settings' -> 'Advanced'
My access token had to be included in the code generated from the Graph API Explorer, like the answer in this post:
(your user access token should be extended to 60 days in the 'Access Token Tool' page by clicking 'debug' -> 'Extend Access Token' and using this token in the code)
The Facebook SDK needs to finish loading before the code generated from the Graph API Explorer is executed, I used Mohammed Arif's answer from this question to do this but I had to use a delay for it to work. I put his code in a function that runs after a 200ms setTimeout, if it is loaded the code generated from the Graph API Explorer executes, else I run the function after a 200ms setTimeout again.
Tobi's answer to part of the question (to get the message) was almost correct: response.data[0].message;

Publish to a page wall using javascript API with a specific user

I'm trying to build a custom post to publish to one of my app facebookpage. I saw in the facebook documentation, the "from" is just a readonly property? theres a way to doit?.
var request = {
message: 'test 1234',
access_token: ACCESS_TOKEN,
from: {
id: MY_APP_ID,
category: "Other",
name: "My great app"
}
};
FB.api('/' + UserPageId + '/feed', post, request);
But instead of the post come from my app, is comming from the "UID" that owns that page.
You have to retrieve an access token as your app. Follow the instructions on the facebook authentication documentation under the section App Login and you will retrieve the correct access token - use that token when making the calls to the api and any action will be executed on behalf of the app.
This is the url to query for an app access token.
https://graph.facebook.com/oauth/access_token?
client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&
grant_type=client_credentials
If you are wanting to publish stories on behalf of a PAGE the process is a little different (its also detailed in the link above). You have to grant the manage_pages permission :
https://www.facebook.com/dialog/oauth?
client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=manage_pages&
response_type=token
And then you can see a list of all the pages the user manages by querying this url :
https://graph.facebook.com/me/accounts?access_token=TOKEN_FROM_ABOVE
It'll give you a list of page names, page ids and page access tokens. Use those tokens to make calls to the graph api on behalf of a page.

Categories

Resources