I want to get a list of all online status (if it is streaming or not) of Twitch team members for a given team name.
My current approach
Get team from API (https://api.twitch.tv/kraken/team/<team name>)
Get stream status for each team member (https://api.twitch.tv/kraken/streams/<channel id>)
My problem with this
First request is okay and works as expected. but I have to request each channel / streamer by it self and not in bulk - and the responded data is more than I really need.
Question
Is there any Twitch API endpoint that I can use, that takes several channel ids and response just a flat dict of channel Id and flag if the streamer is online?
Like:
{[
{ id: 123, online: false },
{ id: 456, online: true}
}]
Solution
Get all of the members _idproperty
Build url like https://api.twitch.tv/helix/streams?user_id=123&user_id=456
Loop over response
If a response's user_id matches an _id -> User is online
Source
discuss.dev.twitch.tv
Related
I am trying to understand how to send mail using Microsoft Graph sendMail API after creating an Azure AD app with 'Application permissions' for Microsoft Graph 'Mail.Send' and 'User.Read'. I am successfully using the client_id, tenant_id and client_secret to obtain an apparently valid token and subsequently submitting a POST to the api like this (R code):
from_address <- "foobar#private.com"
url <- paste0("https://graph.microsoft.com/v1.0/users/", from_address, "/sendMail")
resp <- POST(url,
add_headers(.headers = c(content_type = "application/json",
Authorization = paste("Bearer", token))),
body = upload_file("mail.json"))
The content of "mail.json" is:
{
"message": {
"subject": "Meet for lunch?",
"body": {
"contentType": "Text",
"content": "The new cafeteria is open."
},
"toRecipients": [
{
"emailAddress": {
"address": "someone#somewhere.com"
}
}
]
}
}
However, I get this 404 response:
"{\"error\":{\"code\":\"ErrorInvalidUser\",\"message\":\"The requested user 'foobar#private.com' is invalid.\"}}"
The Microsoft account I am using is private and the address represented above with foobar#private.com is the main 'signin' mail address for the account. I'm not sure if this user needs some special permissions or if it has to be a "corporate account". The plan is to use this within a corporate Microsoft account to send mails but I am currently testing with a private account to determine how it works.
The syntax for the call is
POST /users/{id | userPrincipalName}/sendMail
The tricky part is, as far as I can tell, personal Microsoft accounts don't have a userPrincipalName. Your "foobar#private.com" is an email address, but it isn't used as an identifier within Azure Active Directory or Graph.
Instead, you have to use your ID. You can get this with
GET /me
and the ID is the id field in the response.
Note that you may run into a separate problem with using an email address in the call, when it comes to work & school accounts. Commonly, people will have an address like "firstname.lastname#company.com", but this is only an alias for convenience; their userPrincipalName might be something more cryptic like "id123456#companytenantname.com". For this reason, it's best to stick to IDs throughout.
The description of how to POST to the Microsoft Graph SendMail api are correct in the question. The problem was only in the configuration of the application in Microsoft Azure portal Active directory. The administrator of the tenant created an app with two permissions with 'Admin consent'. The first is a Delegated permission, Microsoft Graph: 'Sign in and read user profile' the second is an Application permission, Microsoft Graph: 'Send mail as any user'. The first is used to get a token that is valid for 1 hour and the second is used in the code you see in the question to send the mail itself with the aquired token. I have been told that there is a restriction in place that only makes it possible to send mail from one specific 'no-reply' address at the organization so you can't use the api to impersonate someone else. It is not clear to me how that restriction works just that is does.
I'm looking for a way to get the user's location, ideally longitude/latitude but address would work too, from the Alexa Skill Kit request to my custom skill. Also, I don't want to have to have the user link to an account on my app's side.
Is this possible? If so, how?
Amazon has now (2017-04-05) added this capability. See their blog post about their new Device Address API.
Using this new API you can get the address (either postal code or full address) of the device, as specified in the customer’s device settings.
From that you could use a geocoding API (such as is part of the Google Maps API) to translate the address into location coordinates.
As per this thread on the Amazon Developer forums, there is not currently (as of May 2016) a way to get user location via the publicly available APIs. The only skills able to do so, such as Uber or Domino's, are utilizing APIs that are not available through the Alexa Skills Kit. However, there's hope that it may be added, as "Jamie#Amazon" left this reply in that discussion:
Hey there,
Thanks for posting.
This has now been added to the roadmap. Thanks for the feedback.
Jamie
However, at the time of writing, no further update has been provided regarding the implementation of such a feature.
As #Tom has pointed out, it is now possible to get the device address in your custom skill. If you are using Python to create your skill, it's pretty easy to implement the new API. I've written a detailed blog post about it here. It also describes how to get the corresponding coordinates for the retrieved address, so it might be useful for you. In short, here is a Python function to get you started. I use the very handy Flask-Ask library for my skill. Thus, it is easy to get the value of the deviceId and consentToken objects. These are included by Alexa in the JSON request sent to your skill. They are needed for constructing the request to the Amazon address API endpoint:
import requests
from flask_ask import Ask, context
def get_alexa_location():
URL = "https://api.amazonalexa.com/v1/devices/{}/settings" \
"/address".format(context.System.device.deviceId)
TOKEN = context.System.user.permissions.consentToken
HEADER = {'Accept': 'application/json',
'Authorization': 'Bearer {}'.format(TOKEN)}
r = requests.get(URL, headers=HEADER)
if r.status_code == 200:
return(r.json())
The function will return something like this on a successful call:
{u'city': u'Berlin', u'countryCode': u'DE',
u'addressLine1': u'42 Unter den Linden',
u'addressLine2': None, u'stateOrRegion': u'Berlin',
u'districtOrCounty': u'Berlin', u'postalCode': u'10117',
u'addressLine3': None}
You can use geopy to convert this address to coordinates.
It is now possible to get the user's real-time geolocation (longitude/latitude) using the Alexa Location Services, which avoids having to integrate with a separate geocoding API as suggested by other answers. See the related blogpost for official information about this feature's release.
Provided that the device is compatible (context.System.device.supportedInterfaces.Geolocation exists), the location services are running and the alexa::devices:all:geolocation:read permission has been granted to your skill , you can retrieve a Geolocation object through the request's context, which will be equivalent to the following JSON payload:
"Geolocation":{
"locationServices": {
"access": "ENABLED",
"status": "RUNNING",
},
"timestamp": "2018-03-25T00:00:00Z+00:00",
"coordinate": {
"latitudeInDegrees": 38.2,
"longitudeInDegrees": 28.3,
"accuracyInMeters": 12.1
},
"altitude": {
"altitudeInMeters": 120.1,
"accuracyInMeters": 30.1
},
"heading": {
"directionInDegrees": 180.0,
"accuracyInDegrees": 5.0
},
"speed": {
"speedInMetersPerSecond": 10.0,
"accuracyInMetresPerSecond": 1.1
}
}
Please follow the below URL to Get location from Alexa Skills Kit (ASK)
URL:
https://api.eu.amazonalexa.com/v1/devices/{devicesId}/settings/address/countryAndPostalCode
Your Header would be something like below :
Host:api.eu.amazonalexa.com[keep your host you can get is from developer account during testing from json]
Accept:application/json
Authorization:Bearer [KEEP YOUR apiAccessToken here]
if request went success your will get response as below:
{
"countryCode": "IN",
"postalCode": "560102"
}
Make sure you have enabled permission in the Alexa app, and grants the permission of the respective skill please refer the bellow URL for more details of permission configuration
https://developer.amazon.com/blogs/alexa/post/0c975fc7-17dd-4f5c-8343-a37024b66c99/alexa-skill-recipe-using-the-device-address-api-to-request-information
I'm trying to load data from the Cloud API, but I don't know when to start my requests from. In the Device API there is "createdDate" key, but its never populated.
Is there a way to find this information from the API without asking the user?
I'm seeing the "createdTime" displaying correctly in my profile when I query the Profile API.
Request:
GET https://api.microsofthealth.net/v1/me/Profile
Response:
{
"firstName":"John",
"lastName":"",
"birthdate":"",
"postalCode":"",
"gender":"Male",
"height":19055,
"weight":549575,
"preferredLocale":"en-US",
"lastUpdateTime":"2016-06-04T00:07:58.950+00:00",
"createdTime":"2015-10-09T18:26:53.498+00:00"
}
Firebase REST API doc has an example of posting a list of data:
curl -X POST -d '{
"author": "alanisawesome",
"title": "The Turing Machine"
}' 'https://docs-examples.firebaseio.com/rest/saving-data/fireblog/posts.json'
the keys are provided in the posted data. Is it possible to just post a list of values and have firebase auto-generate the keys, similar to the javascript example below?
var postsRef = ref.child("posts");
postsRef.push({
author: "gracehop",
title: "Announcing COBOL, a New Programming Language"
});
postsRef.push({
author: "alanisawesome",
title: "The Turing Machine"
});
The Firebase REST API creates one child node for every POST request you send.
The JavaScript snippet you show does the same, it creates one child each time you call push. It's just more efficient, since it only has to establish a connection once, while the REST API sets up a new connection for every request.
You can get the result you're looking for by generating the IDs client-side (the algorithm that Firebase uses to generate its Push IDs is described in this blog post) and then issuing a HTTP PATCH request.
I am working with testing out provisioning for an embedded device where I can't save the API key and feed ID when power cycling.
After activating the product once, I get 403 forbidden when trying to fetch the device API key and feed id for the second time, even though I am supplying a master API key (with read permission) when making the request. The request works however when using API key belonging to the device, which is an inadequate solution considering I don't have access to that API key.
My GET request is formatted as follows:
GET /v2/devices/<activation code>/activate.csv HTTP/1.1
Host: api.xively.com
X-ApiKey: <master API key>
Content-Length: 0
So, is there a way for an already activated device to receive its API key and feed ID?
A device can only be activated once. However, if you have a master key, retrieving the devices API key should be pretty easy. You say you don't know the devices feed ID, but if you used the activation endpoint I imagine you know its serial number?
If you do know its serial number try making a GET request to https://api.cosm.com/v2/products/PRODUCT_ID/devices/DEVICE_SERIAL with your master API key in the X-ApiKey header.
This should return the following JSON, with you feed ID and API key.
{
"device": {
"serial": "SERIAL",
"activation_code": "ACTIVATION_CODE",
"created_at": "2013-05-05T18:11:42Z",
"activated_at": "2013-10-18T16:25:07Z",
"feed_id": FEED_ID,
"api_key": "DEVICE_API_KEY"
}
}
You should also be able to make consecutive activations, if you pass the API key you got from the first activation.