2016-08-07 10 views
1

私はこのようないくつかのコードを見て見ました:のpython:FacebookのGraphAPI要求機能

graph = facebook.GraphAPI(User_Access_Token) 
graph.request("search", {'q' : 'social web', 'type' : 'page'}) 

これは重要な単語「ソーシャルウェブ」を含むすべてのデータをフェッチするようです。しかし私はなぜそのような要求をすることができるのか分かりません。 私はfacebook.GraphAPIインスタンスの

要求(自己、パス、引数=なし、post_args =なし、ファイル=なし、方法=なし)メソッド フェッチ言うヘルプのドキュメント(graph.request)を、読んでグラフAPIで指定されたパス。

「検索」はまったく言及していません。

+0

https://developers.facebook.com/docs/graph-api/using-graph-api/#search – CBroe

答えて

0

私は同じ質問があります。あなたはpip install facebook-sdkもインストールされていると仮定します。あなたのソースがMining the Social Web: Analyzing Data from Facebook, Twitter, LinkedIn, and Other Social Media Sites - Feb 11, 2011 by Matthew A. Russellであると再び仮定します。 facebook-sdkのバージョンはfacebook_sdk-2.0.0です。私は、バージョン管理システムがFacebookのGraphAPIと同じであるかどうかはわかりませんが、そうであれば、そのAPIドキュメントはnot supported anymoreです。 hereからライブラリをダウンロードし、/facebook-sdk-2.0.0/facebook/__init__.pyにこのコードブロックが表示されます。

def request(
      self, path, args=None, post_args=None, files=None, method=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. 

     """ 
     args = args or {} 

     if post_args is not None: 
      method = "POST" 

     # Add `access_token` to post_args or args if it has not already been 
     # included. 
     if self.access_token: 
      # If post_args exists, we assume that args either does not exists 
      # or it does not need `access_token`. 
      if post_args and "access_token" not in post_args: 
       post_args["access_token"] = self.access_token 
      elif "access_token" not in args: 
       args["access_token"] = self.access_token 

     try: 
      response = requests.request(method or "GET", 
             FACEBOOK_GRAPH_URL + path, 
             timeout=self.timeout, 
             params=args, 
             data=post_args, 
             proxies=self.proxies, 
             files=files) 
     except requests.HTTPError as e: 
      response = json.loads(e.read()) 
      raise GraphAPIError(response) 

     headers = response.headers 
     if 'json' in headers['content-type']: 
      result = response.json() 
     elif 'image/' in headers['content-type']: 
      mimetype = headers['content-type'] 
      result = {"data": response.content, 
         "mime-type": mimetype, 
         "url": response.url} 
     elif "access_token" in parse_qs(response.text): 
      query_str = parse_qs(response.text) 
      if "access_token" in query_str: 
       result = {"access_token": query_str["access_token"][0]} 
       if "expires" in query_str: 
        result["expires"] = query_str["expires"][0] 
      else: 
       raise GraphAPIError(response.json()) 
     else: 
      raise GraphAPIError('Maintype was not text, image, or querystring') 

     if result and isinstance(result, dict) and result.get("error"): 
      raise GraphAPIError(result) 
     return result 

私はそれが役に立ちそうです。

関連する問題