I am trying to create a Python program to get channel statisitics, but when I run it the YouTube API website gives this output (error):
{
"error": {
"code": 400,
"message": "'statisitcs'",
"errors": [
{
"message": "'statisitcs'",
"domain": "youtube.part",
"reason": "unknownPart",
"location": "part",
"locationType": "parameter"
}
]
}
}
This is my code:
class YTstats:
def __init__(self, api_key, channel_id):
self.api_key = api_key
self.channel_id = channel_id
self.channel_stats = None
def get_channel_statistics(self):
url = f'https://www.googleapis.com/youtube/v3/channels?part=statisitcs&id={self.channel_id}&key={self.api_key}'
print(url)
API_KEY = 'I cannot share my api key so I am not showing it but it is in my code'
yt = YTstats(API_KEY, 'UCbXgNpp0jedKWcQiULLbDTA')
yt.get_channel_statistics()
This problem is fixed now (it was a typo)
You have a typo here part=statisitcs - as you mentioned in your comment - and after looking closely to the code you provided in your question.
Next time, check closely your code and try to replicate the error using the try-it demo feature in the YouTube Data API documentation.
I do get the statistics of the channel_id you provided - that is: UCbXgNpp0jedKWcQiULLbDTA:
These are their statistics:
"statistics": {
"viewCount": "5642720",
"subscriberCount": "98400",
"hiddenSubscriberCount": false,
"videoCount": "158"
}
}
See the demo here.
Here is the full response:
{
"kind": "youtube#channelListResponse",
"etag": "lG-nYlbLnN81gtjVKe1zKPW6v7A",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#channel",
"etag": "j4Fo8qKbWrLHnQYB8sCI8_I4v9A",
"id": "UCbXgNpp0jedKWcQiULLbDTA",
"snippet": {
"title": "Python Engineer",
"description": "Free Python and Machine Learning Tutorials!\n\nHi, I'm Patrick. I’m a passionate Software Engineer who loves Machine Learning, Computer Vision, and Data Science. I create free content in order to help more people get into those fields. If you have any questions, feedback, or comments, just shoot me a message! I am happy to talk to you :)\n\nIf you like my content, please subscribe to the channel!\n\nPlease check out my website for more information:\nhttps://www.python-engineer.com\n\nIf you find these videos useful and would like to support my work you can find me on Patreon:\nhttps://www.patreon.com/patrickloeber\n\nLegal: https://www.python-engineer.com/legal-notice/\n",
"customUrl": "pythonengineer",
"publishedAt": "2019-05-03T11:22:33Z",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/ytc/AKedOLTs-Pvd4mvUi-m2rDLd8bzrKwS5a8C9HnDbkUDzHw=s88-c-k-c0x00ffffff-no-rj",
"width": 88,
"height": 88
},
"medium": {
"url": "https://yt3.ggpht.com/ytc/AKedOLTs-Pvd4mvUi-m2rDLd8bzrKwS5a8C9HnDbkUDzHw=s240-c-k-c0x00ffffff-no-rj",
"width": 240,
"height": 240
},
"high": {
"url": "https://yt3.ggpht.com/ytc/AKedOLTs-Pvd4mvUi-m2rDLd8bzrKwS5a8C9HnDbkUDzHw=s800-c-k-c0x00ffffff-no-rj",
"width": 800,
"height": 800
}
},
"localized": {
"title": "Python Engineer",
"description": "Free Python and Machine Learning Tutorials!\n\nHi, I'm Patrick. I’m a passionate Software Engineer who loves Machine Learning, Computer Vision, and Data Science. I create free content in order to help more people get into those fields. If you have any questions, feedback, or comments, just shoot me a message! I am happy to talk to you :)\n\nIf you like my content, please subscribe to the channel!\n\nPlease check out my website for more information:\nhttps://www.python-engineer.com\n\nIf you find these videos useful and would like to support my work you can find me on Patreon:\nhttps://www.patreon.com/patrickloeber\n\nLegal: https://www.python-engineer.com/legal-notice/\n"
}
},
"contentDetails": {
"relatedPlaylists": {
"likes": "",
"uploads": "UUbXgNpp0jedKWcQiULLbDTA"
}
},
"statistics": {
"viewCount": "5642720",
"subscriberCount": "98400",
"hiddenSubscriberCount": false,
"videoCount": "158"
}
}
]
}
Try to wait a few minutes after the call you made - probably, the API couldn't retrieve the data you requested due to excessive requests or the channel itself didn't have their statistics publicly available.
Related
I'm working on an Alexa skill using the Alexa Skills Kit, and when the user says an invalid utterance, it replies with 'There was a problem with the requested skill's response'.
I've tried using the AMAZON.Fallback intent, but looking at the json output in the test window shows that it hasn't been triggered.
My backend is python 2.7 in Lambda and I'm using the locale en-gb (I've tried copying the interaction model into en-us but had the same results).
Is fallback intent the right thing to use to handle invalid utterances, or is there another way to achieve similar results?
Here is the Json input:
{
"version": "1.0",
"session": {
"new": false,
"sessionId": "amzn1.echo-api.session.bb6cd858-2128-44d2-8c43-ed6c501e0be4",
"application": {
"applicationId": "amzn1.ask.skill.0fbcbd10-17ee-49ea-9f7a-30401dc26a56"
},
"user": {
"userId": "amzn1.ask.account.AHL5Q4YLTSH3CHSILRWTE6FBK3XLKFE3XR6D6KY45IW6QVKJOW6ZWUAWMVS23YRY6EVWM45DKXPJSOXFP5AJ47TJTFD3JRHGEMUVAMKVZ4GGFJZ35JGAJV22RRDKP534OKVE46QPI32H5T6IJFHDVPP4TC3W6QXDJ2XPTYUL3U2MLQ2NYSG63UE2Q3MJZGJ7GEA5MIKSJCWUPEQ"
}
},
"context": {
"System": {
"application": {
"applicationId": "amzn1.ask.skill.0fbcbd10-17ee-49ea-9f7a-30401dc26a56"
},
"user": {
"userId": "amzn1.ask.account.AHL5Q4YLTSH3CHSILRWTE6FBK3XLKFE3XR6D6KY45IW6QVKJOW6ZWUAWMVS23YRY6EVWM45DKXPJSOXFP5AJ47TJTFD3JRHGEMUVAMKVZ4GGFJZ35JGAJV22RRDKP534OKVE46QPI32H5T6IJFHDVPP4TC3W6QXDJ2XPTYUL3U2MLQ2NYSG63UE2Q3MJZGJ7GEA5MIKSJCWUPEQ"
},
"device": {
"deviceId": "amzn1.ask.device.AGBUICDG5CR3PRTAM43NOEG3QDWUIIPF723CFMXHZILFXJY4CNAUNFVQGH33BL6VRU4DXG667KBEIE66XIO4ZW44DL2O67ALKIJDVV2YF7JPPAZAUZRGI2EHH34KVEHSPZRM3TMLPIAREL4LSTWFSI3MU2JA",
"supportedInterfaces": {}
},
"apiEndpoint": "https://api.eu.amazonalexa.com",
"apiAccessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjEifQ.eyJhdWQiOiJodHRwczovL2FwaS5hbWF6b25hbGV4YS5jb20iLCJpc3MiOiJBbGV4YVNraWxsS2l0Iiwic3ViIjoiY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ajX-3xHs8rjIcdxvnc-w"
},
"Viewport": {
"experiences": [
{
"arcMinuteWidth": 246,
"arcMinuteHeight": 144,
"canRotate": false,
"canResize": false
}
],
"shape": "RECTANGLE",
"pixelWidth": 1024,
"pixelHeight": 600,
"dpi": 160,
"currentPixelWidth": 1024,
"currentPixelHeight": 600,
"touch": [
"SINGLE"
]
}
},
"request": {
"type": "SessionEndedRequest",
"requestId": "amzn1.echo-api.request.33d7948c-e4de-4ec9-9490-8e66c460d8f7",
"timestamp": "2019-02-19T17:33:18Z",
"locale": "en-GB",
"reason": "ERROR",
"error": {
"type": "INVALID_RESPONSE",
"message": "Invalid SSML Output Speech for requestId amzn1.echo-api.request.14165ddf-86dc-4cd2-b636-94df1ddfd835. Error: Fatal error occurred when processing SSML content. This usually happens when the SSML is not well formed. Error: Unexpected character 'T' (code 84) in prolog; expected '<'\n at [row,col {unknown-source}]: [1,1]"
}
}
}
If you're working with a skill that in English or German yes, you should use fallback intent. Other locales do not support it yet.
For en-GB or en-US you need to make sure that AMAZON.FallbackIntent is defined in your voice interaction model (front-end) and that you have an handler in the back-end (eg lambda) to catch intent requests named AMAZON.FallbackIntent
This definitely sound like a problem in your backen-end processiong the fallback intent (you might not be catching it properly)
I am using Openstack Mitaka.
In Django I am trying to get all the resources for tenants. (This is ok)
After that I need to understand the resource type. For example if it is an instance or floating ip, etc.
def sync_resources():
logger.info("Executing sync_resources")
sync_tenants()
tenants = Tenant.objects.all()
managers = Manager.objects.filter(is_active=True)
for manager in managers:
services = manager.services.all()
regions = manager.region_set.all()
for region in regions:
ceilometer_driver = CeilometerDriver(region_name=region.name, **manager.ceilometer_params)
if ceilometer_driver.is_authenticated:
for tenant in tenants:
queries = [ceilometer_driver.make_query("project_id", ceilometer_driver.EQUAL, tenant.tenant_id)]
resource_list = ceilometer_driver.get_resource_list(query=queries)
In this code I get all the resources for a tenant. However I do not need all of them. And I will filter them based on list of types. Such as "Instance, floating_ip, volume, snapshot, etc"
Here is a sample resource detail:
sample resource floating_ip
from the metadata I can see that it is a floating_ip. However I cannot see somewhere in the details that its type floating ip. The metadata changes for different type of resources.
I alsoe checked from terminal with
$ ceilometer resource-list
$ ceilometer resource-show id-of-resource
Again the details are not helpful.
So I need a way to easily understand the resource type and match them with "Instance, floating ip, volume, snapshot, etc."
Additional info:
After some research I realized that I can get the type from link info. This doesn't work with "ceilometerclient" that I am using in the ceilometer_driver.
I can get the additional link info when I call directly from REST API.
Here is a URL to call single project resource:
http://192.168.101.11:8777/v2/resources?q.field=project_id&q.value=63c40f56e11a4d24981710fd46285233
In results below is a sample for instance. I removed most of the links. But one link shows that it is an instance.
{
"user_id": "ec0d0110f44f42608814106a1f921a16",
"links": [
{
"href": "http://192.168.101.11:8777/v2/resources/e4d30a8e-e339-4c47-b71f-ec7061aaf113",
"rel": "self"
},
{
"href": "http://192.168.101.11:8777/v2/meters/instance?q.field=resource_id&q.value=e4d30a8e-e339-4c47-b71f-ec7061aaf113",
"rel": "instance"
},
...
],
"resource_id": "e4d30a8e-e339-4c47-b71f-ec7061aaf113",
"source": "openstack",
"last_sample_timestamp": "2018-03-15T14:18:15.368000",
"first_sample_timestamp": "2017-09-20T11:58:06.704000",
"project_id": "63c40f56e11a4d24981710fd46285233",
"metadata": {
"instance_host": "node-6.reg1.test.skyatlas.com",
"ephemeral_gb": "0",
"flavor.vcpus": "1",
"flavor.ephemeral": "0",
"instance_id": "e4d30a8e-e339-4c47-b71f-ec7061aaf113",
"display_name": "fuel service plugin",
"state": "active",
"flavor.ram": "2048",
"status": "active",
"ramdisk_id": "None",
"flavor.name": "m1.small",
"disk_gb": "20",
"kernel_id": "None",
"image.id": "4905099d-7912-4b00-b5bd-d8e1698dee92",
"flavor.id": "2",
"host": "b26c476c766c058541258e0c9275a738b889e0242be2af62fb331422",
"OS-EXT-AZ.availability_zone": "test-1",
"image.name": "Ubuntu 16.04.3 LTS (Xenial Xerus)",
"image_ref_url": "http://192.168.101.11:8774/images/4905099d-7912-4b00-b5bd-d8e1698dee92",
"name": "instance-00000037",
"flavor.disk": "20",
"root_gb": "20",
"image.links": "[{'href': 'http://192.168.101.11:8774/images/4905099d-7912-4b00-b5bd-d8e1698dee92', 'rel': 'bookmark'}]",
"memory_mb": "2048",
"instance_type": "m1.small",
"vcpus": "1",
"image_ref": "4905099d-7912-4b00-b5bd-d8e1698dee92",
"flavor.links": "[{'href': 'http://192.168.101.11:8774/flavors/2', 'rel': 'bookmark'}]"
}
}
Here is another one for floating ip:
{
"user_id": null,
"links": [
{
"href": "http://192.168.101.11:8777/v2/resources/f61e437d-dce3-4562-bd48-e14a6f0604f3",
"rel": "self"
},
{
"href": "http://192.168.101.11:8777/v2/meters/ip.floating?q.field=resource_id&q.value=f61e437d-dce3-4562-bd48-e14a6f0604f3",
"rel": "ip.floating"
},
{
"href": "http://192.168.101.11:8777/v2/meters/ip.floating.create?q.field=resource_id&q.value=f61e437d-dce3-4562-bd48-e14a6f0604f3",
"rel": "ip.floating.create"
}
],
"resource_id": "f61e437d-dce3-4562-bd48-e14a6f0604f3",
"source": "openstack",
"last_sample_timestamp": "2018-03-15T14:13:01.808000",
"first_sample_timestamp": "2018-02-14T06:33:51.663000",
"project_id": "63c40f56e11a4d24981710fd46285233",
"metadata": {
"status": "DOWN",
"router_id": "None",
"floating_network_id": "3a15b9a4-8f93-4622-80e6-d57cfee53b43",
"fixed_ip_address": "None",
"floating_ip_address": "192.168.103.132",
"port_id": "None"
}
}
so an instance has a link with
"rel": "instance"
and a floating ip has a link with
"rel": "ip.floating"
I think I can sort them out by REST API call instead of using the driver.
However this so called solution does not seem to me the right way to go.
So I still look for a better way of doing it. All the answers and inputs are welcome.
So I have topicIds for a video
[u'/m/0lbxz:/m/04rlf', u'/m/06m6j', u'/m/017bqr', u'/m/05r5c'].
I am trying to translate the list into something like [people, children...]
Is there an API call that takes in a topicID and returns the pertaining topic?
Those are Freebase topics and you can retrieve them using the Freebase topic API https://developers.google.com/freebase/v1/topic-overview you can also dump and build your own local dataset using freebase dumps https://developers.google.com/freebase/data
However I would advise caution on using this, as freebase API has been deprecated.
At any case, here is a simple example on how to retrieve the data that you are looking for
$ curl "https://www.googleapis.com/freebase/v1/search?query=/m/06m6j&indent=true"
{
"status": "200 OK",
"result": [
{
"mid": "/m/06m6j",
"id": "/en/ragtime",
"name": "Ragtime",
"notable": {
"name": "Musical genre",
"id": "/music/genre"
},
"lang": "en",
"score": 20.126026
}
],
"cost": 4,
"hits": 1
}
This is my first time with paypal and I need some help to finish payment integration. I've already tried to contact the paypal support but with no success. Here is my question and I really hope to get some help.
Something very strange grinds my gears and I cannot find why this do that. It's about the user authorization, and specially about paypal json responses. I'm using python sdk but that doesn't matter in this case. Here is my input.
paypalrestsdk.configure({
'mode': 'sandbox',
'client_id': 'XXX',
'client_secret': 'XXX'
})
payment = paypalrestsdk.Payment({
"intent": "authorize",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {
"return_url": "http://mysite/success",
"cancel_url": "http://mysite/cancel"
},
"transactions": [ {
"amount": {
"total": price,
"currency": "USD"
},
"description": title
}]
})
And everything is ОК, except that I doesn't receive an Authorization ID. Here is what I receive as response:
{
'redirect_urls':{
'cancel_url':'http://glamfame.com:8000/cancel',
'return_url':'http://glamfame.com:8000/success'
},
'update_time':'2014-04-08T13:54:22Z',
'state':'created',
'transactions':[
{
'amount':{
'currency':'USD',
'total':'123.00',
'details':{
'subtotal':'123.00'
}
},
'description':'fawfwa',
'related_resources':[{
'authorization':{
'valid_until':'2014-05-07T13:54:22Z',
'update_time':'2014-04-08T13:54:22Z',
'parent_payment':'PAY-54Y91315F8620142DKNB77DQ',
'create_time':'2014-04-08T13:54:22Z',
'links':[{
'method':'GET',
[link removed]
'rel':'parent_payment'
}]
}
}]
}],
'payer':{
'payer_info':{
'shipping_address':{
}
},
'payment_method':'paypal'
},
'id':'PAY-54Y91315F8620142DKNB77DQ',
'intent':'authorize',
'create_time':'2014-04-08T13:54:22Z',
'links':[{ POST, GET, REDIRECT methods with links
}]
And below is what I supposed to receive according their documentation.
{
"id": "2DC87612EK520411B",
"create_time": "2013-06-25T21:39:15Z",
"update_time": "2013-06-25T21:39:17Z",
"state": "authorized",
"amount": {
"total": "7.47",
"currency": "USD",
"details": {
"subtotal": "7.47"
}
},
"parent_payment": "PAY-36246664YD343335CKHFA4AY",
"valid_until": "2013-07-24T21:39:15Z",
"links": [
{
"href": [link removed]
"rel": "self",
"method": "GET"
},
{
"href": [link removed]
"rel": "capture",
"method": "POST"
},
{
"href": [link removed]
"rel": "void",
"method": "POST"
},
{
"href": [link removed]
"rel": "parent_payment",
"method": "GET"
}]
}
As you maybe already noticed, in the paypal response doesn't contain authorization id and void, and capture link. Can you please help me to find out the reason for this. Thank you in advance.
Best Regards,
Georgi
From the REST API documentation: With PayPal payments authorizations, PayPal initially provides HATEOAS links that are specific to PayPal payments including an approval_url and execute link. First get payment approval and execute the payment as you normally would do for a PayPal payment. Once you successfully execute on the payment authorization, PayPal responds with a new set of HATEOAS links, including a capture link that you use to capture the payment.
I am new to freebase. Might be a simple answer but I cant seem to understand the freebase API. I try to run a simple query using the command queryResult = freebase.mqlread(queryFB); and I get the error below. I haven't logged in to the API. I created an account which is a google account. My question is when I call freebase.login(username,password); what do I use? Google account details? I am also attaching my query.
Query:
{
"type": "/food/dish",
"id": dish,
"name": None,
"cuisine":
[{
"id": None,
"name": None,
"region_of_origin":
[{
"id": None,
"name": None,
"/location/location/contains":
[{
"id": None,
"name": city,
"type": "/location/citytown",
"limit": 20
}]
}],
"optional": "optional"
}],
"type_of_dish1":
[{
"id": None,
"name": None,
"optional": "optional"
}]
}
Error:
{
"error":
{
"errors":
[
{
"domain": "usageLimits",
"reason": "userRateLimitExceededUnreg",
"message": "User Rate Limit Exceeded. Please sign up",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "User Rate Limit Exceeded. Please sign up"
}
}
Sounds like you might be using an obsolete client library and/or API. The current API doesn't use a username/password pair, but rather an API key.
Try this. It will explain how to use api key for running MQL. You will need to get only the apikey for freebase. NO username or password is required.
https://developers.google.com/freebase/v1/mql-overview