Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Graph API Version 16 #520

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions facebook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
FACEBOOK_GRAPH_URL = "https://graph.facebook.com/"
FACEBOOK_WWW_URL = "https://www.facebook.com/"
FACEBOOK_OAUTH_DIALOG_PATH = "dialog/oauth?"
VALID_API_VERSIONS = ["3.1", "3.2", "3.3", "4.0", "5.0", "6.0", "7.0", "8.0"]
VALID_API_VERSIONS = ["4.0", "5.0", "6.0", "7.0", "8.0", "9.0", "10.0", "11.0", "12.0", "13.0", "14.0", "15.0", "16.0"]
VALID_SEARCH_TYPES = ["place", "placetopic"]


Expand Down Expand Up @@ -75,13 +75,13 @@ class GraphAPI(object):
"""

def __init__(
self,
access_token=None,
timeout=None,
version=None,
proxies=None,
session=None,
app_secret=None,
self,
access_token=None,
timeout=None,
version=None,
proxies=None,
session=None,
app_secret=None,
):
# The default version is only used if the version kwarg does not exist.
default_version = VALID_API_VERSIONS[0]
Expand All @@ -93,7 +93,7 @@ def __init__(
self.app_secret_hmac = None

if version:
version_regex = re.compile(r"^\d\.\d{1,2}$")
version_regex = re.compile(r"^\d{1,2}\.\d{1,2}$")
match = version_regex.search(str(version))
if match is not None:
if str(version) not in VALID_API_VERSIONS:
Expand Down Expand Up @@ -241,7 +241,7 @@ def get_version(self):
params=args,
timeout=self.timeout,
proxies=self.proxies,
)
)
except requests.HTTPError as e:
response = json.loads(e.read())
raise GraphAPIError(response)
Expand All @@ -254,7 +254,7 @@ def get_version(self):
raise GraphAPIError("API version number not available")

def request(
self, path, args=None, post_args=None, files=None, method=None
self, path, args=None, post_args=None, files=None, method=None
):
"""Fetches the given path in the Graph API.

Expand Down Expand Up @@ -292,7 +292,7 @@ def _add_to_post_args_or_args(arg_name, arg_value):
data=post_args,
proxies=self.proxies,
files=files,
)
)
except requests.HTTPError as e:
response = json.loads(e.read())
raise GraphAPIError(response)
Expand Down Expand Up @@ -344,7 +344,7 @@ def get_app_access_token(self, app_id, app_secret, offline=False):
)["access_token"]

def get_access_token_from_code(
self, code, redirect_uri, app_id, app_secret
self, code, redirect_uri, app_id, app_secret
):
"""Get an access token from the "code" returned from an OAuth dialog.

Expand Down Expand Up @@ -476,7 +476,7 @@ def get_user_from_cookie(cookies, app_id, app_secret):


def parse_signed_request(signed_request, app_secret):
"""Return dictionary with signed request data.
""" Return dictionary with signed request data.

We return a dictionary containing the information in the
signed_request. This includes a user_id if the user has authorised
Expand Down Expand Up @@ -519,4 +519,4 @@ def parse_signed_request(signed_request, app_secret):
if sig != expected_sig:
return False

return data
return data
6 changes: 3 additions & 3 deletions test/test_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def test_no_version(self):
)

def test_valid_versions(self):
for version in facebook.VALID_API_VERSIONS:
graph = facebook.GraphAPI(version=version)
self.assertEqual(str(graph.get_version()), version)
graph = facebook.GraphAPI(version=facebook.DEFAULT_VERSION)
self.assertEqual(str(graph.get_version()), facebook.DEFAULT_VERSION)


def test_invalid_version(self):
self.assertRaises(
Expand Down