Get secret gists using Github GraphQL - github

As title, I'm using Github GraphQL explorer to fetch list of my gists.
query {
viewer {
gists(first:5, privacy:ALL) {
edges {
node {
id
description
name
pushedAt
}
}
}
}
}
Everything works fine except that the secret gists are not included in the response. When I tried to fetch secret gists by changing the GistPrivacy from ALL to SECRET as below:
query {
viewer {
gists(first:5, privacy:SECRET) {
edges {
node {
id
description
name
pushedAt
}
}
}
}
}
The following permission error occurred:
{
"data": {
"viewer": {
"gists": {
"edges": []
}
}
},
"errors": [
{
"message": "You don't have permission to see gists."
}
]
}
I wonder is there any way to solve this problem.
I noticed that there was a related questions with irrelevant answer asked 5 years ago.
Any comment or help is much appreciated, thanks in advance.

As it turns out, although one can't get the secret gists from the Github GraphQL explorer directly, by creating a Personal Access Tokens and using it to access the GraphQL API, one can get the secret gists.
The equivalent curl command is as following:
curl --request POST \
--url https://api.github.com/graphql \
--header 'authorization: Bearer YOUR_PERSONAL_ACCESS_TOKEN' \
--header 'content-type: application/json' \
--data '{"query":"query {\n viewer {\n gists(first:5, privacy:ALL) {\n\t\t\tedges {\n\t\t\t\tnode {\n\t\t\t\t\tid\n\t\t\t\t\tdescription\n\t\t\t\t\tname\n\t\t\t\t\tpushedAt\n\t\t\t\t}\n\t\t\t}\n\t\t}\n }\n}"}'

Related

How can I use Google Apps Script in Unity? [duplicate]

This question is about receiving POST request from somewhere. I'm looking for a google sheet script function that can take and handle data from the POST request in JSON format. Could you suggest any example?
The POST request is here:
https://script.google.com/macros/s/BOdirjv45Dn6FHrx_4GUguuS6NJxnSEeviMHm3HerJl4UsDBnDgfFPO/
{
"p1": "writeTitle",
"p2": [[URL]],
"p3": [[PIC_A]],
"p4": [[PIC_B]],
"p5": [[TITLE]]
}
application/json
doPost() doesn't work:
doPost(e) {
var json = JSON.parse(e.postData.contents);
Logger.log(json);
}
You want to retrieve the value from the request body as an object.
You have already deployed Web Apps.
If my understanding of your situation is correct, how about this modification?
Post and retrieved object:
As a sample, I used the following curl command to POST to Web Apps.
curl -L \
-H 'Content-Type:application/json' \
-d '{"p1": "writeTitle","p2": "[[URL]]","p3": "[[PIC_A]]","p4": "[[PIC_B]]","p5": "[[TITLE]]"}' \
"https://script.google.com/macros/s/#####/exec"
When above command is run, e of doPost(e) is as follows.
{
"parameter": {},
"contextPath": "",
"contentLength": 90,
"queryString": "",
"parameters": {},
"postData": {
"type": "application/json",
"length": 90,
"contents": "{\"p1\": \"writeTitle\",\"p2\": \"[[URL]]\",\"p3\": \"[[PIC_A]]\",\"p4\": \"[[PIC_B]]\",\"p5\": \"[[TITLE]]\"}",
"name": "postData"
}
}
The posted payload can be retrieved by e.postData. From above response, it is found that the value you want can be retrieved by e.postData.contents. By the way, when the query parameter and the payload are given like as follows,
curl -L \
-H 'Content-Type:application/json' \
-d '{"p1": "writeTitle","p2": "[[URL]]","p3": "[[PIC_A]]","p4": "[[PIC_B]]","p5": "[[TITLE]]"}' \
"https://script.google.com/macros/s/#####/exec?key=value"
value can be retrieved by e.parameter or e.parameters. And the payload can be retrieved by e.postData.contents.
Modified script:
In this modified script, the result can be seen at the Stackdriver, and also the result is returned.
function doPost(e) {
var json = JSON.parse(e.postData.contents);
console.log(json);
return ContentService.createTextOutput(JSON.stringify(json));
}
Note:
When you modified your script of Web Apps, please redeploy it as new version. By this, the latest script is reflected to Web Apps. This is an important point.
Reference:
Web Apps
Stackdriver Logging
If this was not what you want, I'm sorry.

Github Rest api : what is the right value of Head field?

I am trying to create a Pull Request, using curl . y
The pull request source and target branch are in the same repo. (Not cros repository).
The source branch name is cd/apim-1.25.27, and the target branch name is master.
I keep having the following error, and tried every possibility for the head field format (the PR source branch name), but still can’t get to create a the PR…
My curl :
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ******" \
https://api.github.com/repos/MY_ORGANIZATION/My_REPOSITORY/pulls \
-d '{"title":"Amazing new feature","body":"Please pull these awesome changes in!","head":"cd/apim-1.25.27","base":"master"}'
I got this message from github api
{
"message": "Validation Failed",
"errors": [
{
"resource": "PullRequest",
"field": "head",
"code": "invalid"
}
],
"documentation_url": "https://docs.github.com/rest/reference/pulls#create-a-pull-request"
I got the issue only using curl.
Creating the pull request with postman works well.
Finally I end up using octokit library, github official development kit (https://octokit.github.io/rest.js/v18#pulls-create).
Below the code I used:
const { Octokit } = require("#octokit/rest");
const octokit = new Octokit({auth: '${GITHUB_PAT_PR}' });
octokit.rest.pulls.create(
{
owner: 'OWNER',
repo: '${REPOSITORY_NAME}',
title: 'Creating new pull request',
body: 'Pull request detailled description',
head: 'source_branche',
base: 'destination_branch'
}).then(data => console.log("The pullrequest was successfuly created!"))
.catch(err => {
let reponseGithub = err.response.data.errors[0];
if(reponseGithub && reponseGithub.message && reponseGithub.message.includes("A pull request already exists for")) {
console.log("A pull request already exists for this repository");
}
else
{
console.log("An unexpected error occurred while creating the pull request on Github");
console.log("check octokit documentation ==> https://octokit.github.io/rest.js/v18#pulls-create ");
console.log("Github API Documentation ==> https://docs.github.com/rest/reference/pulls#create-a-pull-request ");
console.log(err.response.data.errors);
throw new Error('an error message');
}
});

How can I authenticate with google cloud in Unity?

I'm trying to use google automl object detection in a Unity project.
Here is the google curl command example:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
-H "Content-Type: application/json" \
https://automl.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/us-central1/models/model-id:predict \
-d '{
"payload" : {
"image": {
"imageBytes" : "/9j/4AAQSkZJRgABAQAAAQ … "
},
}
}'
After some googling, I start to create a UnityWebRequest to test response:
WWWForm form = new WWWForm();
var postUrl = "https://automl.googleapis.com/v1beta1/projects/1043345783500/locations/us-central1/models/IOD1798528344157847552:predict";
using (UnityWebRequest www = UnityWebRequest.Post(postUrl, form))
{
www.SetRequestHeader("Authorization", #"Bearer $(gcloud auth application-default print-access-token)");
yield return www.SendWebRequest();
if (www.isNetworkError)
{
Debug.Log(www.error);
}
else if (www.isDone)
{
Debug.Log(www.downloadHandler.text);
}
}
So the response from google is:
{
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. 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"
}
}
I understand that, I am not unauthenticated but couldn't understand how I can authenticate. Do I have to make an authentication request? How? Do I have to post something to get an access token? Then where should I send it?
I downloaded some credentials from google server but I really don't have any idea how to use it...

Facebook Chatbot Persistent Menu doesn't work (parameter setting_type is required)

I'm currently trying to implement a Persistent Menu for my Facebook Chatbot. Sadly there are two (completely different) documentation for the implementation which both don't work for me. (Both should work for API v2.6)
https://developers.facebook.com/docs/messenger-platform/messenger-profile/persistent-menu
https://developers.facebook.com/docs/messenger-platform/thread-settings/persistent-menu
I used this simple call which is returning an error (#100) The parameter setting_type is required
curl -X POST -H "Content-Type: application/json" -d '{
"persistent_menu":[
{
"call_to_actions":[
{
"type":"web_url",
"title":"Einstellungen",
"url":"https://{{url-part}}.cloudfront.net/",
"webview_height_ratio":"full"
}
]
},
{
"locale":"de_DE",
"composer_input_disabled":false
}
]
}' "https://graph.facebook.com/v2.6/me/thread_settings?access_token={{token}}"
If I use the second documentation with "setting_type" : "call_to_actions" the same error occurs.
Why I can't set up a Persistent Menu?
The below works for me.
Make sure you are sending the request to the new endpoint, messenger_profile. You have to provide at least a default locale.
curl -X POST -H "Content-Type: application/json" -d '{
"persistent_menu":[
{
"locale":"default",
"composer_input_disabled":false,
"call_to_actions":[
{
"type":"web_url",
"title":"Einstellungen",
"url":"https://{{url-part}}.cloudfront.net",
"webview_height_ratio":"full"
}
]
}
]
}' "https://graph.facebook.com/v2.6/me/messenger_profile?access_token={{token}}"

Weird error with Facebook Messenger Platform/bot Welcome Confugration

I'm getting a weird error while configuring welcome message for my Messenger bot. I've been using the same code (as shown below) and it has just been working fine until last night. I tried it with both cURL and Postman. Neither of them works.
curl -X POST -H "Content-Type: application/json" -d '{
"setting_type":"call_to_actions",
"thread_state":"new_thread",
"call_to_actions":[
{
"message":{
"text":"Welcome to My Company!"
}
}
]
}' "https://graph.facebook.com/v2.6/<PAGE_ID>/thread_settings?access_token=<PAGE_ACCESS_TOKEN>"
Error message when executing the code above:
{"error":{"message":"(#100) Invalid keys \"message\" were found in param \"call_to_actions[0]\".","type":"OAuthException","code":100,"fbtrace_id":"Hn42Wa+hapI"}}%
I can confirm both PAGE_ID and PAGE_ACCESS_TOKEN are correct as trying to delete the welcome message with the following code works fine.
curl -X POST -H "Content-Type: application/json" -d '{
"setting_type":"call_to_actions",
"thread_state":"new_thread",
"call_to_actions":[
{
"message":{
"text":"Welcome to My Company!"
}
}
]
}' "https://graph.facebook.com/v2.6/<PAGE_ID>/thread_settings?access_token=<PAGE_ACCESS_TOKEN>"
Also, the code I'm using is exactly the same as shown on the Facebook official API doc. I don't understand why it's saying "message" is not a valid key. Is anyone experiencing the same problem? Did Facebook change their api?
Any help will be much appreciated!
The docs are now updated, you need to define your payload in payload parameter now (a UTF-8 encoded string), eg:
"call_to_actions":[
{
"payload":"USER_DEFINED_PAYLOAD"
}
]
Docs updated:
https://developers.facebook.com/docs/messenger-platform/thread-settings/greeting-text
Example:
curl -X POST -H "Content-Type: application/json" -d '{
"setting_type":"greeting",
"greeting":{
"text":"Welcome to My Company!"
}
}' "https://graph.facebook.com/v2.6/me/thread_settings?access_token=PAGE_ACCESS_TOKEN"
I get the same issue and fix it.
I think your json of request is
let messageData = {
"setting_type":"call_to_actions",
"thread_state":"new_thread",
"call_to_actions":[
{
"payload":"welcome_payload"
}
]
}
request({
url: 'https://graph.facebook.com/v2.6/me/thread_settings',
qs: {access_token:token},
method: 'POST',
json: {
messageData
}
}
but it will not work and log will say you have no "setting_type" = =a
try this one
request({
url: 'https://graph.facebook.com/v2.6/me/thread_settings',
qs: {access_token:token},
method: 'POST',
json: {
setting_type:"call_to_actions",
thread_state:"new_thread",
call_to_actions:[
{
"payload":"welcome_payload"
}
]
}
}
it work for me.
This error was due to an API change.
New call:
curl -X POST -H "Content-Type: application/json" -d '{
"setting_type":"call_to_actions",
"thread_state":"new_thread",
"call_to_actions":[{
"payload":"START"
}]
}' "https://graph.facebook.com/v2.6/<PAGE_ID>/thread_settings?access_token=<PAGE_TOKEN>"
Just add a payload like {"payload":"START"}
If a user press the "Getting started" button, you receive this payload in your messageHandler (webhook). Check if $incomingMessage == "START" and send back your structured message, or whatever you want.
Messages like before are not supported anymore.
Bug report: https://developers.facebook.com/bugs/1751749508372552/