How to Create a comment using WP Rest API v2? - json

I'm trying to create a new comment via the WP Rest APi v2 using a POST request to the following url:
https://www.turboweb.online/wp-json/wp/v2/comments?author_email=admin#admin.com&author_name=alex bhati&content=nice post&post=4002
But, this is the response I'm getting every time:
{
"code": "rest_forbidden_param",
"message": "Query parameter not permitted: author_email",
"data": {
"status": 401
}
}

The author_email field requires authorization in order to be added, maybe this answer can help: WP Rest API not allowing to post anonymous comments through a Laravel request

Related

Unable to retrieve Claims in either the id_token or userinfo requests

I'm trying to retrieve the CIF and also the Tax Id of the logged in user following your documentation. When trying to request that information via additional claims via the Consumer API, with the scope of &scope=openid I'm supplying the below claims parameter in my authorization request. Making sure that the External App is configured with the claims access in the Banno portal, I don't get anything in my response id_token. I've also attempted to switch this to the userinfo leveraging the opid/me resource which just returns the user "sub".
Claims readable:
claims={"id_token":{"https://api.banno.com/consumer/claim/customer_identifier":null}}
Here it is url encoded:
claims==%7B%22id_token%22%3A%7B%22https%3A%2F%2Fapi.banno.com%2Fconsumer%2Fclaim%2Fcustomer_identifier%22%3Anull%7D%7D
decoded jwt id_token repsonse:
"id_token": {
"header": {
"alg": "RS256",
"typ": "JWT",
"kid": "sig-rs-0"
},
"body": {
"sub": "sub uuid",
"at_hash": "ShHf2gRtROCBdE-j_5YZkw",
"aud": "aud uuid",
"exp": 1668092577,
"iat": 1668088977,
"iss": "https://api.banno.com/a/consumer/api/v0/oidc"
}
}
using the same example switching the claims key to "userinfo" and making a request to .../a/consumer/api/v0/oidc/me I only get this response:
UserInfo Response:
{"sub":"sub uuid"}
In either scenario, I'm expecting the following example to be in the response:
"https://api.banno.com/consumer/claim/customer_identifier": "AAA1234",
However I don't get anything no matter what I do. What am I missing here?
It looks like there is an extra = in the encoded version. If I take what you've posted in the question, claims==%7B%22id_token%22%3A%7B%22https%3A%2F%2Fapi.banno.com%2Fconsumer%2Fclaim%2Fcustomer_identifier%22%3Anull%7D%7D and decode it, I get claims=={"id_token":{"https://api.banno.com/consumer/claim/customer_identifier":null}}, which has an extra = next to the claims parameter name.
That seems to have the effect of the name of the claim not matching up with what is expected, therefore that claim's value is not included in the Identity Token (and isn't available from the UserInfo endpoint).
The Claims in the Identity Token guide will be helpful to review.

Google Chat API: Delete message from bot gives a 401 error

This is the code i'm trying to use for deleting messages posted through a webhook to a chat room (I grab messageID when I create It with this same request but POST method and sending message in a text variable):
var WEBHOOK_URL2 = "https://chat.googleapis.com/v1/spaces/<SPACE>/messages/<MESSAGEID>.<MESSAGEID>?key=<KEY>&token=<TOKEN>%3D";
var options = {
'method' : 'delete',
'muteHttpExceptions' : true,
};
var response = UrlFetchApp.fetch(WEBHOOK_URL2, options);
Logger.log (response);
The response is
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
}
As commented, creating messages works with those credentials (key / token from chatroom webhook) Maybe i am missing something from the documentation at https://developers.google.com/hangouts/chat/reference/rest/v1/spaces.messages/delete ?
Thank you in advance,
That error usually occurs because the request lacks the access token or that access token wasn't validated. I assume that you are using Apps Script for this task. If my assumption is true, you'll find this reference useful; it summarizes the OAuth 2.0 protocol for Google APIs using JavaScript. For obtaining access tokens, please refer to this other guide for a complete step-by-step. Please, follow those steps on your request routine and don't hesitate to write back if you need more help.

How can I trigger a Google Apps Script function from the Google API PHP Client with the authentication I have set already?

I'm struggling to trigger a Google Apps Script Function which builds many dropdowns of a Google Spreadsheet.
I need this data to be updated daily on this Google Spreadsheet so I must call the function.
Seems like I'm required to have a client-side authentication which I'm reluctant to force it to happen.
I have set already the Google API PHP Client which does batch updates, get requests and control users and its roles.
Here's how the code looks like:
public function updateTemplate ()
{
$client = $this->getClient();
$service = new Google_Service_Script($client);
$scriptId = $this->gScriptId;
// Create an execution request object.
$request = new Google_Service_Script_ExecutionRequest();
$request->setFunction('SetUpNewSpreadsheet');
try {
// Make the API request.
$response = $service->scripts->run($scriptId, $request);
echo "here<pre>";
print_r($response);
exit;
I'm getting the following response error:
Caught exception: {
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"errors": [ {
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"domain": "global",
"reason": "unauthorized"
} ]
, "status": "UNAUTHENTICATED"
}
}
I've checked the message errors and docs already. I'm wondering if maybe I'm missing something or if I can find a way to execute that request without forcing a client-side login?
Has anyone been through it?

Chrome Web notification 'MismatchSenderId' error

I have deployed the sample code for Chrome push notifications and updated the gcm_sender_id to a newly configured project, the client is able to subscribe/unsubscribe without issue but when posting a request to send a notification the response MismatchSenderId is continually returned.
I have tried creating multiple new projects console.firebase.google.com, but nothing seems to work.
Request:
POST /gcm/send HTTP/1.1
Host: android.googleapis.com
Authorization: key=<Server Key/>
Content-Type: application/json
{
"registration_ids":[
"<Registration-ID/>"
]
}
Response:
{
"multicast_id": 6881038306061588882,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [
{
"error": "MismatchSenderId"
}
]
}
I am using the 'Server Key' as the request auth token (which works as 401 is returned when an invalid key is used) and am using the 'Sender ID' in the manifest:
manifest.json
{
"name": "Notification Demo",
"gcm_sender_id": "<Sender ID/>"
}
This was my own fault; the sample registration ID's were in a different format to the generated ones I was seeing and did not contain semicolons which I was using to strip the registration ID from the subscription endpoint string. Splitting the endpoint by a forward slash and taking the last instance returned the correct Registration ID which works fine.

Empty response from push notification

I'm getting empty response posts from google drive push notification api. I'm not sure if I'm not looking correctly at the posted data to my listening app or if I'm incorrectly setting up my channels.
I've able to setup channels verified with the responses like:
[14-07-26 14:27:19:697 EDT] {
"kind": "api#channel",
"id": "ce976221-7f6c-44bd-82f3-6a7a539fbc18",
"resourceId": "YTWyD_gD_mUUBM8Ttrqc6P6ZCxI",
"resourceUri": "https://www.googleapis.com/drive/v2/files/1T0GX4lBx6yH2DHMAS624qk5bQylZm1kRs_rE8tIHS_c?updateViewedDate=false&alt=json",
"token": "caller=https://script.google.com/a/macros/ccsknights.org/s/AKfycbxc0JwGl-TptxgsHhWPaAZbIgQXRk7fhB282ReOa09f_6HmGPkw/exec",
"expiration": "1406402836000"
}
And my listening app does receive notifications as I mess with the test document. I do a dump of the entire posted data but it shows up as:
{queryString=null, parameter={}, contextPath=, parameters={}, contentLength=0}
I've posted other data to the app to test it and it shows up as expected:
{queryString=bob/asdasd/asdasdsd/adsad, postData=FileUpload, parameter={test=yes, test2=no, bob/asdasd/asdasdsd/adsad=}, contextPath=, parameters={test=[Ljava.lang.Object;#2fc540bd, test2=[Ljava.lang.Object;#3f1d50cb, bob/asdasd/asdasdsd/adsad=[Ljava.lang.Object;#1da35fcc}, contentLength=17}
The listening app is simply:
var sslog = SpreadsheetApp.openById('1dOic6cWtTuj7lxi-QoRK2hrlXArd2C5ZlqOEmCvJ6R0').getSheets()[0];
function doPost(e) {
sslog.appendRow([e]);
return 200;
//return ContentService.createTextOutput().setContent(JSON.stringify(e)).setMimeType(ContentService.Mi meType.JSON);
}
Is there something I'm missing to be able to extract the push notification data from the post?
The correct answer is the post body is retrieved in the postData object. It was added but not documented. You can find more about it at: https://developers.google.com/apps-script/releases/2013
function doPost(e) {
Logger.log(e.postData.getDataAsString());
}
If you are watching a File resource, POST body is always empty. All of the information that's available to you is contained in "X-Goog-*" headers.