Problems with importing events from Facebook - python

I am to import information about events from Facebook.
I've generated the token, downloaded all the needed libraries.
Here is my code (for example I wanted to download events linked to "Poetry"):
import urllib3
import facebook
import requests
token = 'xyz'
graph = facebook.GraphAPI(access_token = token, version = 2.7)
events = graph.request(‘/search?q=Poetry&type=event&limit=10000’)
Unfortunately an error occurs
How can it be fixed?
I have one more question - how is it possible to download information over some events in a particular location?
I would appreciate any hints or tips.

You need to use apostrophes to enclose a string:
graph.request('/search?q=Poetry&type=event&limit=10000')

Related

How to get account information via using API Binance in Python

I am trying to get account information by using requests library with the code below.
enter image description here
import requests
url = 'https://api.binance.com'
api_get_info = '/sapi/v1/accountSnapshot'
hmac_sha256 = 'api_key'
get_account_info = requests.get(url+api_get_info+api_get_info)
print(get_account_info.text)
I have no idea what the url should be like. Could you guys please give me some idea :)
Binance has an official GitHub repository with examples about these signatures, you can check it out over here: https://github.com/binance/binance-signature-examples/blob/master/python/spot/spot.py
See the function send_signed_request() at the bottom of that file.

Searching keywords using facebook graph API in Python

I recently started working on sentiment analysis for which I need data from Facebook/Instagram post/comment/replies. I plan to search a keyword or tag and would get data from the results. I looked up facebook graph api and some blogs and I found code of 2016 which did exactly that but it isn't working.
import urllib3
import facebook
import requests
token= # mytoken
graph = facebook.GraphAPI(access_token=token, version = 3.1)
events = graph.request('/search?q=Poetry&type=event&limit=10000')
This code finds information on events for any search term say “Poetry” and limiting those events number to 10000
but when I run it I get the following error:
Tell me if it possible and what I should do to fix it.

Reading Outlook calendar events in Python

I need to get the events for the current day from a personal Outlook calendar. I have found next to no feasible resources online besides maybe Microsoft's tutorial (https://learn.microsoft.com/en-us/graph/tutorials/python), but I do not want to build a Django app. Can anyone provide some other resources?
also: I have seen a lot of ppl calling APIs by using a GET <url> command. I cannot for the life of me understand how or where you can use this? Am I missing something crucial when it comes to using APIs?
First you should know that if you wanna call ms graph api, you need to get the access token first and add it to the request header like screenshot below. What I showed in the screenshot is create calendar events but they're similar. Therefore, you can't avoid to generate the token.
Then there're 2 ways lie in front of you, if you are composing a web app, then you can follow this section to find a suitable sample for you, and if you are composing a daemon application, that means you need to use clientcredentialflow here and you may refer to this section.
Anyway, whatever you use SDK or sending http request to call the api, you all need to choose a suitable flow to obtain access token.
For this purpose without using Microsoft Graph API via request in python, there is a PyPI package named O365.
By the following procedure you can easily read a Microsoft calendar:
install the package: pip install O365
register an application in the Microsoft Azure console and keep the application (client) id as well as client secret — this article can help you up.
check the signInAudience, it should be AzureADandPersonalMicrosoftAccount not PersonalMicrosoftAccount within Microsft Azure Manifest, otherwise, you can edit that.
next you should set delegated permission to what scopes you want, in your case it's Calendars.Read. Here's a snapshot of my configuration in Azure:
Now it's time to dive into the code:
from O365 import Account
CLIENT_ID = "xxx"
CLIENT_SECRET = "xxx"
credentials = (CLIENT_ID, CLIENT_SECRET)
scopes = ['Calendars.Read']
account = Account(credentials)
if not account.is_authenticated:
account.authenticate(scopes=scopes)
print('Authenticated!')
schedule = account.schedule()
calendar = schedule.get_default_calendar()
events = calendar.get_events(include_recurring=False)
for event in events:
print(event)

Python response module using PUT with parameters

I'm currently trying to use a RestAPI to set user permissions via a python script. It reads the permission from one server and has to import the permissions of a the same user on another server.
I am using the python requests module and did read up on how to use put with parameters but appear to have issues with the correct syntax.
RestAPI endpoint
the username and permission part is what causes my issue.
I have tried like this:
#!/usr/bin/env python
import requests
payload = (({username}), ({permission}))
set_user_permission_project = requests.put(f'{url}/rest/api/1.0/projects/{row[2]}/permissions/users', auth=(user, pw), params=payload)
And prior to that attempt, I tried it like this:
#!/usr/bin/env python
import requests
set_user_permission_project = requests.put(f'{url}/rest/api/1.0/projects/{row[2]}/permissions/users?{username}&{row[8]}', auth=(user, pw))
Probably I am missing something very essential here and don't get it.
Thanks a lot in advance for your help
Br
After the very useful comments from #estherwn I double checked on the RestAPI and adapted the call accordingly. It was supposed to be key+var as suggested.
Hence the answer for me was:
import requests
set_user_permission_project = requests.put(f'{url}/rest/api/1.0/projects/{row[2]}/permissions/users?name={username}&permission={row[8]}', auth=(user, pw))
I hope someone will find this helpful one day.
Thanks once more for your help #estherwn

Twitter Search Query in Python

I am trying to pull tweets matching the given search query. I'm using the following code :
import urllib2 as urllib
import json
response = urllib.urlopen("https://search.twitter.com/search.json?q=microsoft")
pyresponse = json.load(response)
print pyresponse
This was working a few days ago, but suddenly stopped working now. With some help from google, I learned that this type of url in not supported anymore.
How do I perform this search query. What url shall I use?
Twitter is deprecating non-authenticated searches. You should look into Tweepy or another Python library that interacts with Twitter. https://github.com/tweepy/tweepy

Categories

Resources