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 APINot getting ConversationId of the group in the Group Details APIStack Overflow