I tried to copy public gdrive files to my account by Gdrive API with a simple ps1 script and unix-tools for windows. (curl).
Worked out all required tokens and started to copy,download,delete files that I copied before.
The problem is, I found out that public shared files have different permissions
"capabilities": { "canCopy": true, "canEdit": false },
"editable": false, "copyable": true,
like this link for example:
drive.google.com/open?id=1ArIfiMSmBdlZQUm1cgHi8RRjhSCh8Rym
This is working fine by api request, but if I try to copy files with this permissions
"capabilities": { "canCopy": false, "canEdit": false },
"editable": false, "copyable": false,
drive.google.com/open?id=1cHAsF0D8zEp3LbVB4LmEQbJ3LdU8Cj7i
I get:
"reason": "forbidden",
"message": "Insufficient permissions for the specified parent.",
"locationType": "other",
"location": "parent.permissions" }],
"code": 403,
"message": "Insufficient permissions for the specified parent."
}
}
But in my browser I can rightclick taht file and simply make a copy.
So it seems just not possible by api requests.
But how can I do that by curl/http requests (with stored cookie or someting) ?
$UID = 'clientID.apps.googleusercontent.com'
$skey = 'clientsecret'
$readtoken = (Get-Content "$PSScriptRoot\refreshtoken.txt")
This is to create a fresh accesstoken from stored refreshtoken
$token = curl -d
"client_id=$UID&client_secret=$skey&refresh_token=$readtoken&grant_type=refresh_token"
https://accounts.google.com/o/oauth2/token | grep access_token
$string = $token.TrimStart(""access_token": `"")
$cleantoken = $string.TrimEnd("`",")
$drivefile = Read-Host -Prompt 'Put your Link here'
$driveID =
$drivefile.Substring(33)
$LINKS = curl --request POST
"https://www.googleapis.com/drive/v2/files/$driveID/copy" --header
"Authorization: Bearer $cleantoken" --header "Accept:
application/json" --header "Content-Type: application/json" --data
"{}" --compressed
Related
The API is : /repos/{owner}/{repo}/pulls.
I used the correct token, and the request body is :
data = {
"base": "master",
"head": "owner:master",
"title": "title",
}
The head is like this:
{'Accept': 'application/vnd.github.v3+json', "Authorization": "token {}".format(git_token)}
Then I call the pull API. Returned 200.
<Response [200]>
Why? Maybe the request body wrong?
The Pull Request API specified the answer:
Status: 201 Created
Try and anddapt their example to your repository, to see if it does work:
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/pulls \
-d '{"head":"head","base":"base"}'
Step 1. Get Access Token:
curl --location --request POST 'https://localhost/auth/realms/master/protocol/openid-connect/token' \
--header 'Content-Type: application/x-www-form-url## Heading ##encoded' \
--data-urlencode 'username=*******' \
--data-urlencode 'password=*******' \a
--data-urlencode 'grant_type=*******' \
--data-urlencode 'client_id=*******'
Step 2. Create user and assign a role:
curl --location --request POST 'https://localhost/auth/admin/realms/MyRealm/users' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJKZFVORmNDU19rWjdvZ3ZFSkI4VXZpMTNRb2hKbnh2VW9oeVpieXg2Vld3In0.eyJqdGkiOiI4OGQ4Njk4NC04OGNjLTQzNzAtYWExMC00MTBkYWY5OGY0ODciLCJleHAiOjE1ODQ5NDA2MTYsIm5iZiI6MCwiaWF0IjoxNTg0OTQwNTU2LCJpc3MiOiJodHRwczovL2lkLmRldi1wcm90b24uaXRlcjIwMDQubGFiLmVoZWFsdGguZXhjaGFuZ2UvYXV0aC9yZWFsbXMvbWFzdGVyIiwic3ViIjoiYzI5YjQzMGItMWZlNC00NzJhLWFjYTMtMzgzYTkxNTNmM2RjIiwidHlwIjoiQmVhcmVyIiwiYXpwIjoiYWRtaW4tY2xpIiwiYXV0aF90aW1lIjowLCJzZXNzaW9uX3N0YXRlIjoiNzMyOGUyMDItNzQyZC00ZTdkLTgwMWUtY2UyNGQ1NWUyZDZjIiwiYWNyIjoiMSIsInNjb3BlIjoiZW1haWwgcHJvZmlsZSIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwicHJlZmVycmVkX3VzZXJuYW1lIjoiYWRtaW4ifQ.brCZauRzLeoAHvxtgJy6PYwZhbInVfbLA6HF7YHmwuGzoDoexj97P1s03r2G5bzYUkL93sejEFT5AkPeoZ0gpzHY3IsG3UF7Q9Qvk3t5c08CcAqOn4czhYYV91fwwBWMgTv4sQh0D-_bSq0OtI5g9Ojo0sHzxleYEUW8UYdFsQ_JvpOnZEM87CzUhBqsDDnQ4kPslOaaG2q5PPY3ccNKHexE0UkxjtOeUoIn6tdf-0Yqwc55JCMzWOZmt3pFqWKfm3-VZX5lT0UTL9ktrrLfFTIMfZb-Lmyp2g3_s_juUpkbgPpBPHgh6IGS6XaOnxgseq1Vz4h6pZ_A0O60Z8R5-w' \
--data-raw '{
"username": "ayman",
"enabled": true,
"email": " aymanvirtual#gmail.com",
"firstName": "ayman",
"lastName": "ayman",
"emailVerified":true,
"credentials": [
{
"type": "password",
"value": "ayman"
}
],
"realmRoles": [
"test-role"
]
}'
Step 3. Get user details
curl --location --request GET 'https://localhost/auth/admin/realms/MyRealm/users/d3bbe900-c7b3-49c5-9414-28f9433d3fc1' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJKZFVORmNDU19rWjdvZ3ZFSkI4VXZpMTNRb2hKbnh2VW9oeVpieXg2Vld3In0.eyJqdGkiOiJkMjgzYzA2NS1hMmJjLTQwNDctOWQ0MC01NWI4Nzg5YmNkNGUiLCJleHAiOjE1ODQ5NTM2NDgsIm5iZiI6MCwiaWF0IjoxNTg0OTUzNTg4LCJpc3MiOiJodHRwczovL2lkLmRldi1wcm90b24uaXRlcjIwMDQubGFiLmVoZWFsdGguZXhjaGFuZ2UvYXV0aC9yZWFsbXMvbWFzdGVyIiwic3ViIjoiYzI5YjQzMGItMWZlNC00NzJhLWFjYTMtMzgzYTkxNTNmM2RjIiwidHlwIjoiQmVhcmVyIiwiYXpwIjoiYWRtaW4tY2xpIiwiYXV0aF90aW1lIjowLCJzZXNzaW9uX3N0YXRlIjoiNjhmYmQ1YWQtMTkwMC00MzgyLThiMmYtYjhlYjExOTA4YmFhIiwiYWNyIjoiMSIsInNjb3BlIjoiZW1haWwgcHJvZmlsZSIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwicHJlZmVycmVkX3VzZXJuYW1lIjoiYWRtaW4ifQ.KmWR31pAR4Tl3Mad7awvqeK8np3x5qaPL1tYWAPLDdYaT4nLzpGblmPOBNzYIaEdhs9iwGEmES5_VzrI4C7xUVsY-Zq4jl8iPYP7IawzqgXyrTVuvAO_DLdgdVRKidTT6I-Eh1F87AV14-pOf0GXQ4wnQl5qGl5S6XUTJkegx8eGCg5Qp-zAdHOkxvPL3KRtpgwJx5QCvce-1-wW5Fckk3a-61vXA-o9jUDnJGWTYUyAssVD8zRUs-hhAms1PoR4nW1tCd_9J7xiWmr2hN0-pHY-u5PjNlrxCyOx-3pkRzworZ9e2i0ff0x2dcivpzyDfqe__sdsLVQsiiD1S7ViHw'
Problem:
The user is successfully created but it is not assigned a role (realmRole). After some more research I found that this behaviour is due to a bug in keycloak API (stack overflow issue).
Is there any way to create a user and assign a realm role to it?
Update:
According to some answers, we can use role mappers API calls to map a role to a user. Documentation about those operations: https://www.keycloak.org/docs-api/6.0/rest-api/index.html#_role_mapper_resource
POST /{realm}/groups/{id}/role-mappings/realm
What are the groups in the above URL?
This url: POST /{realm}/groups/{id}/role-mappings/realm is used to assign a realm role to a group where {id} is the group id.
To assign a realm role to a user, use:
# Get the role lists
GET /{realm}/roles
# Get the user lists
GET /{realm}/users
# Assign your role to user
POST /{realm}/users/{userId}/role-mappings/realm
body :[{id: roleId, name: roleName]
your request could be:
curl --location --request POST 'https://localhost/auth/admin/realms/MyRealm/users/MyUserId/role-mappings/realm' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJKZFVORmNDU19rWjdvZ3ZFSkI4VXZpMTNRb2hKbnh2VW9oeVpieXg2Vld3In0.eyJqdGkiOiI4OGQ4Njk4NC04OGNjLTQzNzAtYWExMC00MTBkYWY5OGY0ODciLCJleHAiOjE1ODQ5NDA2MTYsIm5iZiI6MCwiaWF0IjoxNTg0OTQwNTU2LCJpc3MiOiJodHRwczovL2lkLmRldi1wcm90b24uaXRlcjIwMDQubGFiLmVoZWFsdGguZXhjaGFuZ2UvYXV0aC9yZWFsbXMvbWFzdGVyIiwic3ViIjoiYzI5YjQzMGItMWZlNC00NzJhLWFjYTMtMzgzYTkxNTNmM2RjIiwidHlwIjoiQmVhcmVyIiwiYXpwIjoiYWRtaW4tY2xpIiwiYXV0aF90aW1lIjowLCJzZXNzaW9uX3N0YXRlIjoiNzMyOGUyMDItNzQyZC00ZTdkLTgwMWUtY2UyNGQ1NWUyZDZjIiwiYWNyIjoiMSIsInNjb3BlIjoiZW1haWwgcHJvZmlsZSIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwicHJlZmVycmVkX3VzZXJuYW1lIjoiYWRtaW4ifQ.brCZauRzLeoAHvxtgJy6PYwZhbInVfbLA6HF7YHmwuGzoDoexj97P1s03r2G5bzYUkL93sejEFT5AkPeoZ0gpzHY3IsG3UF7Q9Qvk3t5c08CcAqOn4czhYYV91fwwBWMgTv4sQh0D-_bSq0OtI5g9Ojo0sHzxleYEUW8UYdFsQ_JvpOnZEM87CzUhBqsDDnQ4kPslOaaG2q5PPY3ccNKHexE0UkxjtOeUoIn6tdf-0Yqwc55JCMzWOZmt3pFqWKfm3-VZX5lT0UTL9ktrrLfFTIMfZb-Lmyp2g3_s_juUpkbgPpBPHgh6IGS6XaOnxgseq1Vz4h6pZ_A0O60Z8R5-w' \
-d '[
{
"id": "12345678-1234-5678-1234-567812345678",
"name": "admin"
}
]'
I've faced the same issue and corrected it by using a GROUP, Basically, I've added the preferred ROLE into the User Groups ROLE LIST and used that specific user group while creating the user via REST API.
Eg:- ADMIN_USER_GROUP -> INCLUDED ('ADMIN_ROLE')
Then User creation API Request should be like below,
{
"firstName": "Sergey",
"lastName": "Kargopolov",
"email": "test4#test.com",
"enabled": "true",
"credentials": [
{
"value": "123"
}
],
"groups": [
"ADMIN_USER_GROUP"
]
}
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...
I'm attempting to use Google Apps Script to access Salesforce's Bulk API 2.0 and upload the CSV data to a job, however Salesfore is returning
[{"errorCode":"METHOD_NOT_ALLOWED","message":"HTTP Method 'GET' not allowed. Allowed are PUT"}]
Given my experience with the Salesforce API, I highly doubt the issue is actually with the method type, but that there is some other validation which is causing this error. However, upon inspection of the request body and comparing it to what I successfully submit through cURL, I don't see what I can do to resolve.
The request code:
var headers = {
"Authorization": "Bearer TOKEN"
};
var options = {
"method": "put",
"contentType": "text/csv",
"headers": headers,
"payload": "Id,Entity_Name__c\n001,One\n002,Two\n003,Three"
};
var url = INSTANCE + "/services/data/v44.0/jobs/ingest/" + JOB_ID + "/batches";
UrlFetchApp.fetch(url, options);
Google Apps Script request as returned via getRequest():
{
"headers": {
"Authorization": "Bearer TOKEN"
},
"method": "put",
"payload": "Id,Entity_Name__c\n001,One\n002,Two\n003,Three",
"followRedirects": true,
"validateHttpsCertificates": true,
"useIntranet": false,
"contentType": "text/csv",
"url": "INSTANCE/services/data/v44.0/jobs/ingest/JOB_ID/batches"
}
cURL request:
curl --request PUT \
--url INSTANCE/services/data/v44.0/jobs/ingest/JOB_ID/batches \
--header 'authorization: Bearer TOKEN' \
--header 'content-type: text/csv' \
--data '"Id,Entity_Name__c\n001,One\n002,Two\n003,Three"'
How can I resolve this?
I'm trying to use MATLAB's webread function to query Google BigQuery via the REST API, and am having issues. The following curl request is successful:
curl 'https://www.googleapis.com/bigquery/v2/projects/<MyProjectId>/queries' \
-X POST \
-H 'Authorization: Bearer <MyBearerToken>' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data-binary '{"query":"select count(1) from MyTable","useLegacySql":false}' \
--compressed
However, the following MATLAB code:
api = 'https://www.googleapis.com/bigquery/v2/';
access_token = '<MyAccessToken>';
options = weboptions('RequestMethod', 'post');
r = webread([api 'projects/<MyProjectId>/queries?access_token=' access_token], ...
'query', 'select count(1) from MyTable', ...
'useLegacySql', false, ...
options);
generates the following error:
Error using readContentFromWebService (line 45)
The server returned the status 400 with message "Bad Request" in response to the request to URL
https://www.googleapis.com/bigquery/v2/projects/<MyProjectId>/queries?access_token=<MyAccessToken>&query=select+count(1)+from+<MyTable>&useLegacySql=0
Entering the URL in the MATLAB error into a POST requester shows the following (generic) error, so it appears the URL is malformed:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Required parameter is missing"
}
],
"code": 400,
"message": "Required parameter is missing"
}
}
How can I use MATLAB's webread to accomplish the same thing as the above curl request?
It turns out that the webread function doesn't have this functionality. This issue is resolved successfully by using webwrite as follows:
options = weboptions( ...
'RequestMethod', 'post', ...
'MediaType', 'application/json');
data = struct( ...
'query', 'select count(1) from MyTable', ...
'useLegacySql', false);
r = webwrite([api 'projects/<MyProjectId>/queries?access_token=' access_token], ...
data, ...
options);