Esempio n. 1
0
 def get_contacts(self, rpc=None):
     request = self._client.GetContacts(rpc=rpc)
     if rpc is not None:
         from geouser.models import urlfetch
         return urlfetch.make_fetch_call(rpc,
                                         str(request.uri),
                                         headers=request.headers)
     return request
Esempio n. 2
0
    def request(self, path, args=None, post_args=None, rpc=None):
        """Fetches the given path in the Graph API.

        We translate args to a valid query string. If post_args is given,
        we send a POST request to the given path with the given arguments.
        """
        if not args: args = {}
        if self.access_token:
            if post_args is not None:
                post_args["access_token"] = self.access_token
            else:
                args["access_token"] = self.access_token
        post_data = None if post_args is None else urllib.urlencode(post_args)
        if rpc is not None:
            return urlfetch.make_fetch_call(
                rpc,
                "https://graph.facebook.com/" + path + "?" +
                urllib.urlencode(args),
                method='GET' if post_data is None else 'POST',
                payload=post_data)

        response, content = self.req.request(
            "https://graph.facebook.com/" + path + "?" +
            urllib.urlencode(args),
            method='GET' if post_data is None else 'POST',
            body=post_data)
        try:
            content = _parse_json(content)
        except:
            raise OAUTHException("Can't parse json")
        if response['status'] == 400:
            token = OAUTH_Access.get_token(self.access_token)
            if token is not None:
                if token.user.twitter_user is not None:
                    token.user.facebook_user.delete()
                token.delete()
            raise GraphAPIError(content["error"]["type"],
                                content["error"]["message"])
        if response['status'] != 200:
            raise GraphAPIError(content["error"]["type"],
                                content["error"]["message"])
        if response['content-type'].startswith('text'):
            return content
        if response['content-type'].startswith('image'):
            content = {
                "data": content,
                "mime-type": response['content-type'],
                "url": response['url'],
            }
        raise GraphAPIError('Response Error', 'Maintype was not text or image')
Esempio n. 3
0
 def get_friends(self, rpc=None):
     twitterInfo = self.get_user_info()
     if rpc is not None:
         from geouser.models import urlfetch
         return urlfetch.make_fetch_call(rpc, self.url_friends + '?user_id=%s&screen_name=%s' % (
                                                    twitterInfo['id'], 
                                                    twitterInfo['screen_name']
                                                    ),
                                         method='GET'
                                         )
     return self._do_request(self.url_friends + '?user_id=%s&screen_name=%s' % (
                                                                    twitterInfo['id'], 
                                                                    twitterInfo['screen_name']
                                                                    ))
Esempio n. 4
0
    def request(self, path, args=None, post_args=None, rpc=None):
        """Fetches the given path in the Graph API.

        We translate args to a valid query string. If post_args is given,
        we send a POST request to the given path with the given arguments.
        """
        if not args: args = {}
        if self.access_token:
            if post_args is not None:
                post_args["access_token"] = self.access_token
            else:
                args["access_token"] = self.access_token
        post_data = None if post_args is None else urllib.urlencode(post_args) 
        if rpc is not None:
            return urlfetch.make_fetch_call(rpc, "https://graph.facebook.com/" + path + "?" +
                                            urllib.urlencode(args), 
                                            method='GET' if post_data is None else 'POST',
                                            payload=post_data)
                 
        response, content = self.req.request("https://graph.facebook.com/" + path + "?" +
                                            urllib.urlencode(args), 
                                            method='GET' if post_data is None else 'POST',
                                            body=post_data)
        try:
            content = _parse_json(content)
        except:
            raise OAUTHException("Can't parse json")
        if response['status'] == 400:
            token = OAUTH_Access.get_token(self.access_token)
            if token is not None:
                if token.user.twitter_user is not None:
                    token.user.facebook_user.delete()
                token.delete()
            raise GraphAPIError(content["error"]["type"],
                                content["error"]["message"])
        if response['status'] != 200:
            raise GraphAPIError(content["error"]["type"],
                                content["error"]["message"])
        if response['content-type'].startswith('text'):
            return content
        if response['content-type'].startswith('image'):
            content = {
                "data": content,
                "mime-type": response['content-type'],
                "url": response['url'],
            }
        raise GraphAPIError('Response Error', 'Maintype was not text or image')
Esempio n. 5
0
 def get_contacts(self, rpc=None):
     request = self._client.GetContacts(rpc=rpc)
     if rpc is not None:
         from geouser.models import urlfetch
         return urlfetch.make_fetch_call(rpc, str(request.uri), headers=request.headers)
     return request