This return all of my post
SELECT post_id, actor_id, target_id, message, likes FROM stream WHERE source_id = me()
but I'd want to get all posts a user sees on its Newsfeed. Is that possible?
I've tried this:
SELECT post_id, actor_id, target_id, message, likes FROM stream
but I get
{ "error": {
"message": "(#601) Parser error: unexpected end of query.",
"type": "OAuthException",
"code": 601 } }
FQL queries need a WHERE clause.
You could use the news feed stream filter: … WHERE filter_key = 'nf'
Related
I am trying to get data about a song playing on one of my devices from the spotify API. I have created a view that fetches data from the API and part of it looks like this:
class Song(viewsets.ModelViewSets):
....
room_code = request.data['room_code']
room = Room.objects.filter(code=room_code)[0]
host = room.host
endpoint = 'player/currently-playing'
response = execute_spotify_api_request(host, endpoint)
item = response.get('item')
duration = item.get('duration_ms')
progress = response.get('progress_ms')
album_cover = item.get('album').get('images')[0].get('url')
return Response(response, status=status.HTTP_200_OK)
The execute_spotify_api_request(host, endpoint) is a utility function and it looks like this:
def execute_spotify_api_request(session_id, endpoint, post_=False, put_=False):
tokens = get_user_tokens(session_id)
headers = {'Content-Type': 'application/json',
'Authorization': "Bearer " + tokens.access_token}
if post_:
post(BASE_URL + endpoint, headers=headers)
if put_:
post(BASE_URL + endpoint, headers=headers)
response = get(BASE_URL, {}, headers=headers)
try:
return response.json()
except:
return {'error': 'Could not retrieve a response'}
The full url from which im fetching is ""https://api.spotify.com/v1/me/player/currently-playing"
The problem is with the response that im getting from the API, the response is not an error but data that im not expecting to get. Im getting a response that looks like this:
response = {
"display_name": "Tanatswamanyakara",
"external_urls": {
"spotify": "https://open.spotify.com/user/dlnsysel6bndktbvduz6cl79w"
},
"followers": {
"href": null,
"total": 0
},
"href": "https://api.spotify.com/v1/users/dlnsysel6bndktbvduz6cl79w",
"id": "dlnsysel6bndktbvduz6cl79w",
"images": [],
"type": "user",
"uri": "spotify:user:dlnsysel6bndktbvduz6cl79w"
}
I was hoping to get data (the progress, title, duration, album, artist etc) about the song I am playing on my spotify account but instead I get that response, how do I fix that?
N.B
My access tokens and refresh tokens are working as they should. (so I think)
If the data is not what you are expecting then there's going to be something wrong with your API endpoint. You can use the Spotify developer console to generate the endpoint link, it would be worth debugging your execute_spotify_api_request code and the url it generates against the value in the console.
Having just re-read your code half way through answering, I've noticed that you aren't appending your endpoint variable to your GET url:
response = get(BASE_URL, {}, headers=headers)
This means that the get doesn't have 'player/currently-playing' and just returns the base URL which is probably 'https://api.spotify.com/v1/me/' - hence the response you receive is just your profile data.
I'm using Postman app to interact with a Telegram bot api. I've sent photos using the sendPhoto() method, like this:
https://api.telegram.org/botToken/sendPhoto?chat_id=00000000&photo=AgAC***rgehrehrhrn
But I don't understand the sendMediaGroup() method. Can someone post an example how to compose the https string to send two photos?
Thanks
You need to send a POST request at the url https://api.telegram.org/botToken/sendPhoto with a JSON body. You are using the url to specify all the parameters of the request but urls are only 2000 characters long. The body of a POST request, instead, has no limits in terms of size. The JSON body should look something like this:
{
"chat_id": 777000,
"media": [
{
"type": "photo",
"media": "https://example.com/first_photo_url.png",
"caption": "an optional description of the first photo",
"parse_mode": "optional (you can delete this parameter) the parse mode of the caption"
},
{
"type": "photo",
"media": "https://example.com/fsecond_photo_url.png",
"caption": "an optional description of the second photo",
"parse_mode": "optional (you can delete this parameter) the parse mode of the caption"
}
],
}
For more info see:
how to send JSON (raw) data with Postman
and
sendMediaGroup Telegram API's method.
You must send JSON as a string, or serialized JSON, to Telegram API. The format is as same as #GioIacca9's answer.
Note: only the caption in the first image will be showen.
Have a try this Python code.
def send_photos(api_key, chat_id, photo_paths):
params = {
'chat_id': chat_id,
'media': [],
}
for path in photo_paths:
params['media'].append({'type': 'photo', 'media': path})
params['media'] = json.dumps(params['media'])
url = f'https://api.telegram.org/bot{api_key}/sendMediaGroup'
return requests.post(url, data=params)
if __name__ == '__main__':
send_photos('your_key', '#yourchannel', ['http://your.image.one', 'http://your.image.two'])
I'm using explorer to test this request "::page_id::?fields=id,name,emails", but it returns this error message:
{
"error": {
"message": "(#100) Tried accessing nonexisting field (emails) on node type (PlaceInformation)",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "Hzq4cKMXlI1"
}
}
I already tried to use contact_email and user_support_email, but it also didn't work.
What is the right field to get page email?
Take a close look at the error message, it says node type (PlaceInformation). I assume you are trying to use a Place, not a Page. Those are the fields available for Places: https://developers.facebook.com/docs/graph-api/reference/place/
I was looking at documentation but I am maybe missing something. If I want to receive certain fields in the request's data, how can I define them? I'd like to avoid the POST or GET method to be executed if the complete fields are not in the request's data.
Example:
I need to receive (application/json):
{
"city": "Port Orange",
"state": "FL",
"formatted_address": "Peach Blossom Blvd 5329",
"_zip": "32128"
}
But if I get only
{
"city": "Port Orange",
"state": "FL",
"formatted_address": "Peach Blossom Blvd 5329"
}
I'd like return a Response with an error message 400 Bad Request. But without executing the POST method. How could I do this?
PS. I am using APIView
Do something like this
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
In your view, return the serializer errors along with the correct status code from rest_framework.status
i want to get each post id with all comments for a page using fql query.if i use -
SELECT text,post_id FROM comment WHERE post_id IN(SELECT post_id FROM stream WHERE source_id=page_id_here)
this returns -
{
"data": [
{
"text": "Would be nice if my website would let me do the update. It says I have the most current version 2.5.9 :(",
"post_id": "2211155996_10151336546425997"
},
{
"text": "All of mine just started showing the update message in the last hour and just got the emails from Admin tools.",
"post_id": "2211155996_10151336546425997"
},
........continues
as you see it returns text and post_id in one object.what i want is there will be post_id and its all comments in one object.hope i get answer as i am struggling for a hour.It's something to do with multi queries with join