当前位置: 首页>>代码示例>>Python>>正文


Python facebook.GraphAPI方法代码示例

本文整理汇总了Python中facebook.GraphAPI方法的典型用法代码示例。如果您正苦于以下问题:Python facebook.GraphAPI方法的具体用法?Python facebook.GraphAPI怎么用?Python facebook.GraphAPI使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在facebook的用法示例。


在下文中一共展示了facebook.GraphAPI方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: forwards

# 需要导入模块: import facebook [as 别名]
# 或者: from facebook import GraphAPI [as 别名]
def forwards(self, orm):
        batch_size = 100
        fb = facebook.GraphAPI(settings.FACEBOOK_APP_ACCESS_TOKEN)
        fb_uids = [str(fb_uid) for fb_uid in orm.FacebookUser.objects.values_list('fb_uid', flat=True)]
        for batch_start in range(0, len(fb_uids), batch_size):
            print batch_start, 'to', min(batch_start+batch_size, len(fb_uids))
            fb_results = fb_call(lambda: fb.get_objects(fb_uids[batch_start:batch_start+batch_size]))
            genders = defaultdict(lambda: [])
            for fb_uid, fb_user_info in fb_results.items():
                if not hasattr(fb_user_info, 'get'):
                    print "Facebook fucked up", repr(fb_uid), '=>', repr(fb_user_info)
                else:
                    genders[Gender.from_string(fb_user_info.get('gender', ''))].append(fb_uid)
            
            for gender, gendered_uids in genders.items():
                orm.FacebookUser.objects.filter(fb_uid__in=gendered_uids).update(gender=gender) 
开发者ID:canvasnetworks,项目名称:canvas,代码行数:18,代码来源:0117_get_gender_from_facebook.py

示例2: do_init

# 需要导入模块: import facebook [as 别名]
# 或者: from facebook import GraphAPI [as 别名]
def do_init(self):
        app_id = self.get_configuration('facebook_app_id')
        app_secret = self.get_configuration('facebook_app_secret')
        app_access_token = self.get_configuration('facebook_access_token')
        if app_id and app_secret and app_access_token:
            params = {
                'client_id': app_id,
                'client_secret': app_secret,
                'grant_type': 'fb_exchange_token',
                'fb_exchange_token': app_access_token
            }
            r = self.requests.get("https://graph.facebook.com/oauth/access_token", params=params)
            if r.ok:
                oauth_access_token = r.json()['access_token']
                self.oauth_access_token = self.write_configuration('facebook_oauth_token', oauth_access_token)
                self.graph = facebook.GraphAPI(oauth_access_token)
                return True
        return False 
开发者ID:SlapBot,项目名称:stephanie-va,代码行数:20,代码来源:facebook_module.py

示例3: handle

# 需要导入模块: import facebook [as 别名]
# 或者: from facebook import GraphAPI [as 别名]
def handle(self, *args, **options):
        api = facebook.GraphAPI(
            access_token=self.config.fb_share_token, version=settings.FACEBOOK_SHARE_GRAPH_API_VERSION
        )
        url = self.config.fb_share_link

        for pet in Pet.objects.get_unpublished_pets():
            api.put_object(
                parent_object="me",
                connection_name="feed",
                message=self.get_message(pet),
                link=url.format(pet.get_absolute_url()),
            )

            pet.published = True
            pet.save() 
开发者ID:jllorencetti,项目名称:pets,代码行数:18,代码来源:shareonfacebook.py

示例4: generate_access_app

# 需要导入模块: import facebook [as 别名]
# 或者: from facebook import GraphAPI [as 别名]
def generate_access_app(server, config, path):
    if not config["app_id"] or not config["app_secret"]:
        server.send_response(500, "Error")
        server.end_headers()

        server.wfile.write(bytes("app_id or app_secret not set", "UTF-8"))
        return True

    access_token = facebook.GraphAPI().get_app_access_token(
        config["app_id"],
        config["app_secret"]
    )

    server.send_response(200, "OK")
    server.end_headers()

    server.wfile.write(bytes(access_token, "UTF-8"))
    return True 
开发者ID:qsniyg,项目名称:rssit,代码行数:20,代码来源:facebook.py

示例5: __init__

# 需要导入模块: import facebook [as 别名]
# 或者: from facebook import GraphAPI [as 别名]
def __init__(self, api):
        token = api["access_token"]
        id = api["id"]
        self.graph = facebook.GraphAPI(token) 
开发者ID:shobeir,项目名称:GraphiPy,代码行数:6,代码来源:facebook_api.py

示例6: get_facebook_account_email

# 需要导入模块: import facebook [as 别名]
# 或者: from facebook import GraphAPI [as 别名]
def get_facebook_account_email(token: str) -> str:
    facebook_api = GraphAPI(token)
    facebook_account = facebook_api.get_object(id='me?fields=email')

    return facebook_account['email'] 
开发者ID:MycroftAI,项目名称:selene-backend,代码行数:7,代码来源:auth.py

示例7: set_graph

# 需要导入模块: import facebook [as 别名]
# 或者: from facebook import GraphAPI [as 别名]
def set_graph(self, oauth_access_token=None):
        if oauth_access_token:
            self.oauth_access_token = oauth_access_token
        self.graph = facebook.GraphAPI(self.oauth_access_token) 
开发者ID:SlapBot,项目名称:stephanie-va,代码行数:6,代码来源:facebook_module.py

示例8: get_api

# 需要导入模块: import facebook [as 别名]
# 或者: from facebook import GraphAPI [as 别名]
def get_api(access_token):
    global graphs
    if access_token not in graphs:
        graphs[access_token] = facebook.GraphAPI(access_token)

    return graphs[access_token] 
开发者ID:qsniyg,项目名称:rssit,代码行数:8,代码来源:facebook.py

示例9: get_vidinfo

# 需要导入模块: import facebook [as 别名]
# 或者: from facebook import GraphAPI [as 别名]
def get_vidinfo(videoID):
    try:
        try:
            graph = facebook.GraphAPI()
            vidObject = graph.get_object(videoID)
            video_url = vidObject['source']
        except facebook.GraphAPIError:
            sys.exit('error : unable to reach facebook')


        url_h = urllib2.urlopen(video_url)
        meta  = url_h.info()
        size  = meta['Content-Length']
        content_type = meta['content-type']
        format = re.search('video/(\w+)', content_type).group(1)
        if vidObject.has_key('name'):
            filename = ''.join(e for e in vidObject['name'] if e.isalnum())
        else:
            filename = None
    except urllib2.URLError:
        sys.exit('error : unable to retrieve video info')


    info = {'url':video_url, 'name':filename, 'size':size, 'format':format}
    return info


#downloads the video 
开发者ID:LarbiBekka34,项目名称:fb-video-dl,代码行数:30,代码来源:fb-video-dl.py

示例10: get_user

# 需要导入模块: import facebook [as 别名]
# 或者: from facebook import GraphAPI [as 别名]
def get_user(self):
        """
        Override this method by sublcassing the class.

        """
        if not current.session.token:
            return None
        return dict(first_name='Pinco',
                    last_name='Pallino',
                    username='pincopallino')
        raise NotImplementedError("Must override get_user()")

        # Following code is never executed.  It can be used as example
        # for overriding in subclasses.
        if not self.accessToken():
            return None

        if not self.graph:
            self.graph = GraphAPI((self.accessToken()))

        user = None
        try:
            user = self.graph.get_object("me")
        except GraphAPIError:
            current.session.token = None
            self.graph = None

        if user:
            return dict(first_name=user['first_name'],
                        last_name=user['last_name'],
                        username=user['id']) 
开发者ID:uwdata,项目名称:termite-visualizations,代码行数:33,代码来源:oauth20_account.py

示例11: _get_credentials

# 需要导入模块: import facebook [as 别名]
# 或者: from facebook import GraphAPI [as 别名]
def _get_credentials(self, code=''):
        logger.info("Tautulli Notifiers :: Requesting access token from {name}.".format(name=self.NAME))

        app_id = plexpy.CONFIG.FACEBOOK_APP_ID
        app_secret = plexpy.CONFIG.FACEBOOK_APP_SECRET
        redirect_uri = plexpy.CONFIG.FACEBOOK_REDIRECT_URI

        try:
            # Request user access token
            api = facebook.GraphAPI(version='2.12')
            response = api.get_access_token_from_code(code=code,
                                                      redirect_uri=redirect_uri,
                                                      app_id=app_id,
                                                      app_secret=app_secret)
            access_token = response['access_token']

            # Request extended user access token
            api = facebook.GraphAPI(access_token=access_token, version='2.12')
            response = api.extend_access_token(app_id=app_id,
                                               app_secret=app_secret)

            plexpy.CONFIG.FACEBOOK_TOKEN = response['access_token']
        except Exception as e:
            logger.error("Tautulli Notifiers :: Error requesting {name} access token: {e}".format(name=self.NAME, e=e))
            plexpy.CONFIG.FACEBOOK_TOKEN = ''

        # Clear out temporary config values
        plexpy.CONFIG.FACEBOOK_APP_ID = ''
        plexpy.CONFIG.FACEBOOK_APP_SECRET = ''
        plexpy.CONFIG.FACEBOOK_REDIRECT_URI = ''

        return plexpy.CONFIG.FACEBOOK_TOKEN 
开发者ID:Tautulli,项目名称:Tautulli,代码行数:34,代码来源:notifiers.py

示例12: _post_facebook

# 需要导入模块: import facebook [as 别名]
# 或者: from facebook import GraphAPI [as 别名]
def _post_facebook(self, **data):
        if self.config['group_id']:
            api = facebook.GraphAPI(access_token=self.config['access_token'], version='2.12')

            try:
                api.put_object(parent_object=self.config['group_id'], connection_name='feed', **data)
                logger.info("Tautulli Notifiers :: {name} notification sent.".format(name=self.NAME))
                return True
            except Exception as e:
                logger.error("Tautulli Notifiers :: Error sending {name} post: {e}".format(name=self.NAME, e=e))
                return False

        else:
            logger.error("Tautulli Notifiers :: Error sending {name} post: No {name} Group ID provided.".format(name=self.NAME))
            return False 
开发者ID:Tautulli,项目名称:Tautulli,代码行数:17,代码来源:notifiers.py

示例13: get_fb_api

# 需要导入模块: import facebook [as 别名]
# 或者: from facebook import GraphAPI [as 别名]
def get_fb_api(request):
    fb_user = facebook.get_user_from_cookie(request.COOKIES,
                                            Config['facebook']['app_id'],
                                            Config['facebook']['secret'])
    access_token = fb_user and fb_user.get('access_token')
    if not access_token:
        raise NotLoggedIntoFacebookError()

    return fb_user, facebook.GraphAPI(access_token) 
开发者ID:canvasnetworks,项目名称:canvas,代码行数:11,代码来源:util.py

示例14: _get_fb_user_from_access_token

# 需要导入模块: import facebook [as 别名]
# 或者: from facebook import GraphAPI [as 别名]
def _get_fb_user_from_access_token(cls, access_token):
        fb = GraphAPI(access_token)
        try:
            fb_user = fb.get_object('me')
            return fb, fb_user
        except GraphAPIError:
            raise ServiceError("There appears to be an issue communicating with Facebook. "
                               "Please try logging in again.") 
开发者ID:canvasnetworks,项目名称:canvas,代码行数:10,代码来源:models.py

示例15: notify_friends_of_signup

# 需要导入模块: import facebook [as 别名]
# 或者: from facebook import GraphAPI [as 别名]
def notify_friends_of_signup(self, access_token):
        fb = GraphAPI(access_token)
        friends = fb.get_object('me/friends')['data']
        fb_friends = FacebookUser.objects.filter(fb_uid__in=[friend['id'] for friend in friends])
        Actions.facebook_friend_joined(self.user, fb_friends) 
开发者ID:canvasnetworks,项目名称:canvas,代码行数:7,代码来源:models.py


注:本文中的facebook.GraphAPI方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。