나는 임의의 인수를 함수에 전달하려고 노력하고 있으며 오류가 계속되고 있으며 어디에서 잘못 될지 확실하지 않습니다. ** kwargs를 사용하려고 시도한 것은 이번이 처음입니다.
보다 구체적으로, Facepy Library를 사용하여 Facebook의 그래프 API에서 데이터를 얻으려고합니다. 문서에 따르면 (https://facepy.readthedocs.org/en/latest/usage/graph-api.html), get
메소드는 "이후", "~"등과 같은 선택적 매개 변수를 수락해야합니다. 주어진 쿼리에서 이러한 매개 변수 중 일부만 전달하려면 ** kwargs를 사용하기에 이상적인 시간처럼 보입니다.
먼저 FacePy 라이브러리를 감싸는 함수를 만듭니다.
def graph_retriever(object_id, metric_url, **kwargs):
#optional args that I want to pass include since, until, and summary
graph = facepy.GraphAPI(access_token)
retries = 3 # An integer describing how many times the request may be retried.
object_data = graph.get('%s/%s' % (object_id, metric_url), False, retries, **kwargs)
return object_data
다음은 다른 인수로 기능을 호출하는 두 가지 예입니다.
for since, until in day_segmenter(start, end): # loop through the date range
raw_post_data = graph_retriever(str(page), 'posts', {'since': since, 'until': until})
post_dict['comment_count'] = graph_retriever(post_id, 'comments', {'summary':1})['summary']['total_count']
그러나 이것을 실행하려고하면 다음과 같은 오류가 발생합니다.
Traceback (most recent call last):
raw_post_data = graph_retriever(str(page), 'posts', {'since': since, 'until': until})
TypeError: graph_retriever() takes exactly 2 arguments (3 given)
내가 뭘 잘못하고 있죠?