admin管理员组文章数量:1392101
I want to obtain the conversation messages from the group. While I am able to retrieve all the data from the group, the conversation_id is missing. As a member, I can access the conversations, but since the group_id and conversation_id are different, I am unable to link the conversations to their respective groups...
Essentially, I need a conversation ID for the group, so I can link this conversation to this group...
import requests
import json
import csv
# Constants
GRAPH_URL_PREFIX = '/'
COMMUNITY_SUFFIX = 'community'
FIELDS_CONJ = '?fields='
GROUPS_SUFFIX = '/groups'
GROUP_FIELDS = 'id,name,admins{id,name,email},members.limit(0).summary(true),privacy,description,updated_time'
JSON_KEY_DATA = 'data'
JSON_KEY_PAGING = 'paging'
JSON_KEY_NEXT = 'next'
# Methods
def getAllGroups(access_token):
endpoint = GRAPH_URL_PREFIX + COMMUNITY_SUFFIX + GROUPS_SUFFIX + FIELDS_CONJ + GROUP_FIELDS
return getPagedData(access_token, endpoint, [])
def getNotPagedData(access_token, endpoint):
headers = buildHeader(access_token)
result = requests.get(endpoint,headers=headers)
return json.loads(result.text)
def getPagedData(access_token, endpoint, data):
headers = buildHeader(access_token)
result = requests.get(endpoint,headers=headers)
result_json = json.loads(result.text)
json_keys = result_json.keys()
if JSON_KEY_DATA in json_keys and len(result_json[JSON_KEY_DATA]):
data.extend(result_json[JSON_KEY_DATA])
if JSON_KEY_PAGING in json_keys and JSON_KEY_NEXT in result_json[JSON_KEY_PAGING]:
next = result_json[JSON_KEY_PAGING][JSON_KEY_NEXT]
if next:
getPagedData(access_token, next, data)
return data
def processAdminsAndMembers(group_data):
for idx, group in enumerate(group_data):
group_data[idx]['members'] = group['members']['summary']['total_count']
admins = ''
try:
for admin in group['admins']['data']:
admins += admin['id'] + '-' + admin['name']
try:
admins += ' (' + admin['email'] + ')|'
except:
admins += '|'
group_data[idx]['admins'] = admins
except:
return group_data
return group_data
def buildHeader(access_token):
return {'Authorization': 'Bearer ' + access_token, "User-Agent": "GithubRep-GroupsWithDetails"}
def exportToCSV(group_list):
keys = group_list[0].keys()
with open('group_export.csv', 'w', newline='\n') as file:
dict_writer = csv.DictWriter(file, fieldnames=keys, delimiter=',', quotechar='"', escapechar='\\', extrasaction='ignore')
dict_writer.writeheader()
dict_writer.writerows(group_list)
## START
access_token = 'access_token'
group_data = processAdminsAndMembers(getAllGroups(access_token))
print (group_data)
exportToCSV(group_data);
版权声明:本文标题:Meta Workplace Graph API - Not getting Conversation_Id of the group in the Group Details API - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744767890a2624153.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论