Google Fit API Cannot add most of the scopes - php

I am using the Google Fit REST API for our current project. We can add some of the data sources but there are some we cannot add. We already followed the documentations. Some of the request are returning this kind of error message (we even tried in their OAuth playground)
"error": {
"status": "INVALID_ARGUMENT",
"message": "Data type does not match well-known data type with the same name",
"code": 400,
"errors": [
{
"reason": "invalidArgument",
"message": "Data type does not match well-known data type with the same name",
"domain": "global"
}
]
}
What we are trying to add is this data source which we already allow the permission scopes of
https://www.googleapis.com/auth/fitness.activity.read
https://www.googleapis.com/auth/fitness.activity.write
{
"application": {
"name": "PersonalPulse",
"version": "1.0.0"
},
"dataType": {
"name": "com.google.activity.exercise",
"field": [
{
"name": "exercise",
"format": "integer"
},
{
"name": "repetitions",
"format": "integer"
},
{
"name": "resistance type",
"format": "integer"
},
{
"name": "resistance",
"format": "floatPoint"
},
{
"name": "duration",
"format": "integer"
}
]
},
"device": {
"manufacturer": "browser",
"model": "browser",
"type": "unknown",
"uid": "2",
"version": "10"
},
"type": "derived"
}
We followed the instructions based on the documentations here
https://developers.google.com/fit/datatypes/activity#workout
We are using PHP/Laravel framework for the fitness api and cURL for the http requests. If someone got an idea why we got the error please help. Thanks.
You can also try in the google playground here and paste the scopes https://developers.google.com/oauthplayground/

The first problem with your request is that you're passing in the exercise is an integer field, but the documentation says that you need to pass in one of an enumerated set of strings (I don't know why it says int there, but if you click the "Accepted values", you can see those definitely aren't integers...).
However, it would be easier if you didn't specify the fields at all. Simply specify the data type name:
// ...
"dataType": {
"name": "com.google.activity.exercise",
}
// ...
and the correct fields will be filled in on the backend and returned to you.

Related

Send Current URL link to A Discord Webhook

So, basically I need a way to send the current URL link to A Discord webhook.
So for example, the URL would be https://www.example.com and I need that link to send to my Discord webhook.
Is there any way someone could help me with this? If this is not possible, are there any alternative methods?
I would recommend you first reading this—it explains in detail how to format the payload so that it renders as a message in Discord properly, you can even use markdown!
Second, I'm not sure what language you want to code this in, but here's a simple example using Python and httpx
The idea to take away here is
Pick a client library
Study the Discord webhook message format
Create a client for HTTP
Set the logic to send the payload to the webhook you want
Create and send the payload with the formatted webhook message in a POST request
data = {
"username": "Webhook",
"avatar_url": "https://i.imgur.com/4M34hi2.png",
"content": "Text message. Up to 2000 characters.",
"embeds": [
{
"author": {
"name": "Birdie♫",
"url": "https://www.reddit.com/r/cats/",
"icon_url": "https://i.imgur.com/R66g1Pe.jpg"
},
"title": "Title",
"url": "https://google.com/",
"description": "Text message. You can use Markdown here. *Italic* **bold** __underline__ ~~strikeout~~ [hyperlink](https://google.com) `code`",
"color": 15258703,
"fields": [
{
"name": "Text",
"value": "More text",
"inline": true
},
{
"name": "Even more text",
"value": "Yup",
"inline": true
},
{
"name": "Use `\"inline\": true` parameter, if you want to display fields in the same line.",
"value": "okay..."
},
{
"name": "Thanks!",
"value": "You're welcome :wink:"
}
],
"thumbnail": {
"url": "https://upload.wikimedia.org/wikipedia/commons/3/38/4-Nature-Wallpapers-2014-1_ukaavUI.jpg"
},
"image": {
"url": "https://upload.wikimedia.org/wikipedia/commons/5/5a/A_picture_from_China_every_day_108.jpg"
},
"footer": {
"text": "Woah! So cool! :smirk:",
"icon_url": "https://i.imgur.com/fKL31aD.jpg"
}
}
]
}
import httpx # pip install httpx, or poetry add httpx
with httpx.Client() as client:
request = client.post("https://www.discordwebhook.com", data=data) # needs to be a POST
print(request.status_code)

PHP Quickbooks SDK - Batch requests and handling failures

I've building out a small app that connects to a Quickbooks API via an SDK. The SDK provides batch operations to help reduce the number of API requests needed.
However, I'm hoping to make a large amount of requests (ie: bulk deletes, uploads in the 100s/1000s). I've gotten the deletes to work, however, now I'm hoping to integrate Laravel's Queue system so that any items in the $batch that fail (due to these business-rules or other reasons) are sent to a worker who will reattempt them after waiting a minute .
Below is an example of a delete request.
class QuickBooksAPIController extends Controller
{
public function batchDelete(Request $request, $category)
{
$chunks = array_chunk($request->data, 30);
foreach ($chunks as $key => $value) {
$batch[$key] = $this->dataService()->CreateNewBatch();
foreach ($value as $id) {
$item = $this->dataService()->FindById($category, $id);
$batch[$key]->AddEntity($item, $id, "delete");
}
$batch[$key]->Execute();
}
return response()->json(['message' => 'Items Deleted'], 200);
}
}
The documentations are a bit sparse for my scenario though. How can I get the failed batch items on order to try again?
Is using batches even the right choice here? Because I have to hit the API anyway to get the $item... which doesn't make sense to me (I think I'm doing something wrong there).
EDIT:
I intentionally sent out a request with more then 30 items and this is the failure message. Which doesn't have the values that didn't make the cut.
EDIT#2:
Ended up using array_chunk to separate the payload into 30 items (which is the limit of the API). Doing so helps process many requests. I've adjusted my code above to represent my current code.
How can I get the failed batch items on order to try again?
If you look at Intuit's documentation, you can see that the HTTP response the API returns contains this information. Here's the example request they show:
{
"BatchItemRequest": [
{
"bId": "bid1",
"Vendor": {
"DisplayName": "Smith Family Store"
},
"operation": "create"
},
{
"bId": "bid2",
"operation": "delete",
"Invoice": {
"SyncToken": "0",
"Id": "129"
}
},
{
"SalesReceipt": {
"PrivateNote": "A private note.",
"SyncToken": "0",
"domain": "QBO",
"Id": "11",
"sparse": true
},
"bId": "bid3",
"operation": "update"
},
{
"Query": "select * from SalesReceipt where TotalAmt > '300.00'",
"bId": "bid4"
}
]
}
And the corresponding response:
{
"BatchItemResponse": [
{
"Fault": {
"type": "ValidationFault",
"Error": [
{
"Message": "Duplicate Name Exists Error",
"code": "6240",
"Detail": "The name supplied already exists. : Another customer, vendor or employee is already using this \nname. Please use a different name.",
"element": ""
}
]
},
"bId": "bid1"
},
{
"Fault": {
"type": "ValidationFault",
"Error": [
{
"Message": "Object Not Found",
"code": "610",
"Detail": "Object Not Found : Something you're trying to use has been made inactive. Check the fields with accounts, customers, items, vendors or employees.",
"element": ""
}
]
},
"bId": "bid2"
},
{
"Fault": {
"type": "ValidationFault",
"Error": [
{
"Message": "Stale Object Error",
"code": "5010",
"Detail": "Stale Object Error : You and root were working on this at the same time. root finished before you did, so your work was not saved.",
"element": ""
}
]
},
"bId": "bid3"
},
{
"bId": "bid4",
"QueryResponse": {
"SalesReceipt": [
{
"TxnDate": "2015-08-25",
"domain": "QBO",
"CurrencyRef": {
"name": "United States Dollar",
"value": "USD"
},
"PrintStatus": "NotSet",
"PaymentRefNum": "10264",
"TotalAmt": 337.5,
"Line": [
{
"Description": "Custom Design",
"DetailType": "SalesItemLineDetail",
"SalesItemLineDetail": {
"TaxCodeRef": {
"value": "NON"
},
"Qty": 4.5,
"UnitPrice": 75,
"ItemRef": {
"name": "Design",
"value": "4"
}
},
"LineNum": 1,
"Amount": 337.5,
"Id": "1"
},
{
"DetailType": "SubTotalLineDetail",
"Amount": 337.5,
"SubTotalLineDetail": {}
}
],
"ApplyTaxAfterDiscount": false,
"DocNumber": "1003",
"PrivateNote": "A private note.",
"sparse": false,
"DepositToAccountRef": {
"name": "Checking",
"value": "35"
},
"CustomerMemo": {
"value": "Thank you for your business and have a great day!"
},
"Balance": 0,
"CustomerRef": {
"name": "Dylan Sollfrank",
"value": "6"
},
"TxnTaxDetail": {
"TotalTax": 0
},
"SyncToken": "1",
"PaymentMethodRef": {
"name": "Check",
"value": "2"
},
"EmailStatus": "NotSet",
"BillAddr": {
"Lat": "INVALID",
"Long": "INVALID",
"Id": "49",
"Line1": "Dylan Sollfrank"
},
"MetaData": {
"CreateTime": "2015-08-27T14:59:48-07:00",
"LastUpdatedTime": "2016-04-15T09:01:10-07:00"
},
"CustomField": [
{
"DefinitionId": "1",
"Type": "StringType",
"Name": "Crew #"
}
],
"Id": "11"
}
],
"startPosition": 1,
"maxResults": 1
}
}
],
"time": "2016-04-15T09:01:18.141-07:00"
}
Notice the separate response object for each request.
The bId value is a unique value you send in the request, which is then echo'd back to you in the response, so you can match up the requests you send with the responses you get back.
Here's the docs:
https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/batch#sample-batch-request
Is using batches even the right choice here?
Batches make a lot of sense when you are doing a lot of things all at once.
The way you're trying to use them is... weird. What you should probably be doing is:
Batch 1
- go find all your items
Batch 2
- delete all the items
Your existing code doesn't make sense because you're trying to both find the item and delete the item in the exact same batch HTTP request, which isn't possible via the API.
I intentionally sent out a request with more then 30 items and this is the failure message.
No, it's not. That's a PHP error message - you have an error in your code.
You need to fix the PHP error, and then look at the actual response you're getting back from the API.

"URL Can't Be Used" error in adding facebook post with child_attachments via api

i'm trying to make a post on facebook using api with using child_attachments param, so i can pass multiple urls in 1 post.
In facebook debugger i'm passing json like that
{
"message": "test debug",
"child_attachments": [
{
"link": {
"link": "https://google.com"
}
},
{
"link": {
"link": "https://ft.com"
}
}
]
}
but i'm getting following error message
{ "error": {
"message": "Invalid parameter",
"type": "OAuthException",
"code": 100,
"error_data": {
"blame_field_specs": [
[
"child_attachments[0][link]"
]
]
},
"error_subcode": 2061006,
"is_transient": false,
"error_user_title": "URL Can't Be Used",
"error_user_msg": "The URL you entered, \"https://google.com\" doesn't direct to a website. Please enter a valid URL and try again.",
"fbtrace_id": "xxxxxxxx"
}
}
i've tried setting urls in app domains , i tried use urls with / without https and with/without www.
still no luck, can some one give me some advise?
Thanks,
Roman.
ok, so i figured, the correct format should be like that:
{
"message": "message to post",
"link": "https://yahoo.com",
"child_attachments": [
{
"link": "https://yahoo.com",
"name": "name -1",
"picture": "https://images.all-free-download.com/images/graphiclarge/ethereal_image_185195.jpg"
},
{
"link": "https://google.com",
"name": "name - 2 ",
"picture": "https://images.all-free-download.com/images/graphiclarge/ethereal_image_185195.jpg"
}
]
}
note that even despite of the thing you adding links in the child_attachments, you must provide 'link' parameter also for post

Facebook - Get & Display me/og.likes in Video application

Have built an video app that publish user actions towards Facebook.
In this app i have implemented an "Favorite" function that i have hooked up towards a basic open graph action "og.like"
I want to be able to display video's that user liked and apply my own styling to that.
Basically i want to display "Title" "Url" & "Image"
So i use the PHP-SDK towards authored user with active access token and execute
$response = $facebook->api(
'me/og.likes',
'GET'
);
// handle the response
How do i now sort out my correct fields and display them ?
Am not hardcore at either php or javascript but will be able to sort this out if i just can get a little push in the right direction. Like just showing the raw data
Update
Finally a little progress, adding
print_r ($response);
Will write out the raw data, Now i know that am on the right way.
Array returned
{
"data": [
{
"id": "123",
"from": {
"name": "Mathias",
"id": "APP_ID"
},
"start_time": "X",
"end_time": "X",
"publish_time": "X",
"application": {
"name": "APP_Name",
"namespace": "",
"id": "321"
},
"data": {
"object": {
"id": "139",
"url": "Url to like",
"type": "video.tv_show",
"title": "title"
}
},
"type": "og.likes",
"no_feed_story": false,
"likes": {
"count": 0,
"can_like": true,
"user_likes": false
},
"comments": {
"count": 0,
"can_comment": true,
"comment_order": "chronological"
}
},
And then the next..
From every app "like" i would like to display Url ,Title & Image
From what i understand so far my main problem is that this is nested arrays, Did try with single level arrays and there i did manage to display correct data just by
echo $response[name];
So how do i digg in and loop this around, All tips are welcome,
{
"id": "139",
"url": "url",
"type": "video.tv_show",
"title": "titke",
"image": [
{
"url": "image_URL",
"secure_url": "image_URL",
"type": "image/jpg",
"width": 1024,
"height": 576
}
Here's an example:
<?php foreach ( $response['data'] as $data ): ?>
<?php $Object = $data['data']['object']; ?>
<?php echo $Object['title']; ?><br />
<?php endforeach; ?>

Error in json_decode

I have the following json, I'm sending through AJAX, but in the server side the json_decode returning an empty array. I'm sending different values as well, and in that case it's working fine. I check int this link, and this is a valid JSON.
[
{
"name": "bettype",
"value": "All"
},
{
"name": "bookies",
"value": "Interwetten"
},
{
"name": "sporttype",
"value": "Soccer"
},
{
"name": "team1",
"value": "Braunschweig"
},
{
"name": "team2",
"value": "Bayern Munich"
},
{
"name": "league",
"value": "Germany DFB Cup (90`)"
}
]
UPDATED:
this is the server side code:
var_dump((stripslashes($_GET['data']));
var_dump(json_decode(stripslashes($_GET['data'])));
and this is the output:
string(244) "[{"name":"bettype","value":"All"},{"name":"bookies","value":"Interwetten"},{"name":"sporttype","value":"Soccer"},{"name":"team1","value":"Braunschweig"},{"name":"team2","value":"Bayern Munich"},{"name":"league","value":"Germany DFB Cup (90�)"}]" NULL
It works fine for me.
http://sandbox.phpcode.eu/g/80941.php
Check your browser configuration/charset and try again

Categories