Getting "message": "No permission to read data for this private data source." for TYPE_LOCATION_SAMPLE and TYPE_LOCATION_TRACK - google-fit

can anyone please let me know how this issue can be solved, is this scope issue or something else.
URL : https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate
"error": {
"status": "PERMISSION_DENIED",
"message": "No permission to read data for this private data source.",
"code": 403,
"errors": [
{
"reason": "forbidden",
"message": "No permission to read data for this private data source.",
"domain": "global"
}
]
}
}```

You first need access to GPS, so you should add the permission to your manifest.xml file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fitness.sync">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
....
And in your code you should pass the permissions to the sign-in account as follows:
public void signIn(){
FitnessOptions fitnessOptions = FitnessOptions.builder()
// add your read & write permissions here
.addDataType(DataType.TYPE_LOCATION_SAMPLE, FitnessOptions.ACCESS_READ)
.addDataType(DataType.TYPE_LOCATION_SAMPLE, FitnessOptions.ACCESS_WRITE)
.addDataType(DataType.TYPE_LOCATION_TRACK, FitnessOptions.ACCESS_READ)
.addDataType(DataType.TYPE_LOCATION_TRACK, FitnessOptions.ACCESS_WRITE)
...
.build();
GoogleSignInAccount account = GoogleSignIn.getAccountForExtension(this, fitnessOptions);
if (!GoogleSignIn.hasPermissions(account, fitnessOptions)) {
GoogleSignIn.requestPermissions(
this, // your activity
GOOGLE_FIT_PERMISSIONS_REQUEST_CODE, // e.g. 1
account,
fitnessOptions);
}
}

Related

Creating a Plan in Planner

I want to create a plan in Planner. The endpoint I call is:
https://graph.microsoft.com/beta/planner/plans
In return I get:
{
"error": {
"code": "",
"message": "You do not have the required permissions to access this item, or the item may not exist.",
"innerError": {
"request-id": "2654b7da-4ee4-47b8-83f8-e9514088c095",
"date": "2018-10-01T10:57:34"
}
}
}
My permissions and scopes are:
SCOPES = ['User.Read', 'Group.ReadWrite.All']
I gave Admin Consent for these permissions.
As a payload I send:
{
"title": "test",
"owner": "<myID>"
}
Where <myID> is the ID of the account requested per /me
Still it does not work - what did I miss?
The owner property should be a Group's id, not the User's id. Users can only have one individual "plan". Since this already exists, you cannot create a new one.
From the documentation:
In the request body, supply a JSON representation of plannerPlan object. The owner property must be set to an id of a group object.

how to Create subscription for sent items folder using Microsoft graph api

following post request give an error when creating a subscription for the Sent Items folder using Microsoft Graph
var apiUrl = "https://graph.microsoft.com/v1.0/subscriptions";
Request
{
"resource": "me/mailFolders('Sent Items')/messages",
"changeType": "created,updated,deleted",
"clientState": "320a6f10-9c62-4e59-a395-8cd27941b597",
"notificationUrl": "https://webhook.site/aaaa-6f49-4906-aaaa-e911f9391695",
"expirationDateTime": "2018-08-28T12:53:41.4830081+00:00"
}
Error Response
{
"error": {
"code": "ExtensionError",
"message": "Operation: Create; Exception: [Status Code: BadRequest; Reason: Bad Request]",
"innerError": {
"request-id": "359f51a6-5b12-41f6-8a02-a68ba4c10585",
"date": "2018-08-27T06:42:18"
}
}
}
Unfortunately the webhook.site test site that you are using does not implement the validation token protocol that is required to setup a subscription. The webhook must return the value of the validationToken query parameter in the response body for the subscription to be created correctly.
i changed the resource property value for folder name 'Sent Items' to 'SentItems' . here is the working request
{
"resource": "me/mailFolders('SentItems')/messages",
"changeType": "created,updated,deleted",
"clientState": "320a6f10-9c62-4e59-a395-8cd27941b597",
"notificationUrl": "https://webhook.site/aaaa-6f49-4906-aaaa-e911f9391695",
"expirationDateTime": "2018-08-29T12:53:41.4830081+00:00"
}

Not getting Authorization dialog for App Script accessing BigQuery Service

I am trying to fix some App Scripts which use the BigQuery "Advanced Service" to install some BigQuery jobs. The first new script I ran popped a BigQuery authorization dialog, and everything worked fine, now running hourly. The second new script ran initially, but is now failing with:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
This began about 12 hours after the initial authorization, so it seems like something expired. But, I can't figure out how to trigger the authorization dialog to appear. Also, I expected an authorization would be required for each distinct function, yet the second one initially ran without asking for BigQuery permissions.
Additional Info:
Here is the .gs file I am executing:
function runQuery() {
var projectId = redacted;
var configuration = {
"query": {
"useQueryCache": false,
"destinationTable": {
"projectId": projectId,
"datasetId": redacted,
"tableId": redacted
},
"writeDisposition": "WRITE_TRUNCATE",
"createDisposition": "CREATE_IF_NEEDED",
"allowLargeResults": true,
"query": redacted
}
};
var job = {
"configuration": configuration
};
var jobResult = BigQuery.Jobs.insert(job, projectId);
var jobId = jobResult.jobReference.jobId;
Logger.log(jobResult);
}
The first time I ran a very similar query, I got a dialog prompting me for BigQuery permissions, as documented here:
https://developers.google.com/apps-script/guides/services/authorization
I subsequently ran this same script successfully (with slightly different query config). But, then, about 12 hours after first run, I started getting the authorization return quoted above. I thought it might refresh with time, but still get same failure.
Turns out this has been working all along. The authorization error was being generated by my attempt to look at the job results, not by the job itself. Doh!

Update user's properties (aboutMe, skills) with app permission

When I am trying to update the user's aboutMe property via /v1.0/users/[user-principal-name] I get following error message:
{
"error":
{
"code": "-1, Microsoft.Office.Server.Directory.DirectoryObjectUnauthorizedAccessException",
"message": "Attempted to perform an unauthorized operation.",
"innerError":
{
"request-id": "a0112fff-de9a-4917-b627-c4103a04a105",
"date": "2018-03-22T11:02:46"
}
}
}
What I have done far:
Added application permissions User.ReadWrite.All and Directory.ReadWrite.All to registered app under apps.dev.microsoft.com
Concent for app was granted by admin via https://login.microsoftonline.com/[tenant]/adminconsent?client_id=[client-id]&state=12345&redirect_uri=[redirect-uri]
I am able to update the user's profile image or a property like mobilePhone.
What am I doing wrong/is it not possible to update those attributes?

Google Search Console 401 Bad Request issue without using Client Library

So, Here are 3 steps.
I called oAuth2 with following url:
https://accounts.google.com/o/oauth2/v2/auth
?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fwebmasters%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fwebmasters.readonly
&client_id=___.apps.googleusercontent.com
&redirect_uri=urn:ietf:wg:oauth:2.0:oob
&response_type=code
&approval_prompt=force
&access_type=offline
I get the code, suppose: 4/QVgPaCMqp94____qBC4NY_d54IcRj7U9mJc
Then I'm making a request for access_token, by making a POST request to https://accounts.google.com/o/oauth2/token with client_id, client_secret, redirect_uri, grant_type, and I get a JSON like:
'access_token' => ya29.CjHzAgC4js6Guv-1pt_rE____q8XIxiXOXOaSZW9NLRjKCTI3izBi,
'expires_in' => 3600,
'refresh_token' => 1/dL3ENA-EVI0rEb6D-OGqw_____iFe2ZNdEq4,
Now, I am making a request with that access_token or in cases of expiry with a renewed access_token to Google Search Console, which I have added in scopes.
My request is similar to this: https://developers.google.com/webmaster-tools/v3/urlcrawlerrorssamples/list#try-it
But I get an 401 unauthorized error, with a json like following:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
Considering I have done the process correctly, I think I have missing some parameters or providing some wrong value.
I have not used Google Client Library, instead used the REST API framework directly.
Can anybody give some clue please? Thank you.
The reason is, URL query parameter must be ?access_token= and not ?key= The later can be used only in case of direct API access and not oAuth.