Edits history of script submission #8865 for ' Retrieves Comments on Comments (linkedin)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Linkedin = {
    	token: string
    	apiVersion: string
    }
    
    export async function main(
    	resource: Linkedin,
    	activityUrn: string, // e.g. urn:li:activity:6273189577469632512
    	commentId: string // e.g. 6275822846992351232
    ) {
    	const pathParam = `urn:li:comment:(${activityUrn},${commentId})`
    	// encodeURIComponent does not encode parenthesis, so using replace for that.
    	const encodedPathParam = encodeURIComponent(pathParam).replace(/\(/g, '%28').replace(/\)/g, '%29')
    
    	const endpoint = `https://api.linkedin.com/rest/socialActions/${encodedPathParam}/comments`
    
    	const response = await fetch(endpoint, {
    		method: 'GET',
    		headers: {
    			Authorization: `Bearer ${resource.token}`,
    			'X-Restli-Protocol-Version': '2.0.0',
    			'LinkedIn-Version': `${resource.apiVersion}`
    		}
    	})
    
    	if (!response.ok) {
    		throw new Error(`HTTP error! status: ${response.status}`)
    	}
    
    	const data = await response.json()
    
    	return data
    }
    

    Submitted by hugo697 689 days ago

  • nativets
    type Linkedin = {
    	token: string
    	apiVersion: string
    }
    
    export async function main(
    	resource: Linkedin,
    	activityUrn: string, // e.g. urn:li:activity:6273189577469632512
    	commentId: string // e.g. 6275822846992351232
    ) {
    	const pathParam = `urn:li:comment:(${activityUrn},${commentId})`
    	// encodeURIComponent does not encode parenthesis, so using replace for that.
    	const encodedPathParam = encodeURIComponent(pathParam).replace(/\(/g, '%28').replace(/\)/g, '%29')
    
    	const endpoint = `https://api.linkedin.com/rest/socialActions/${encodedPathParam}/comments`
    
    	const response = await fetch(endpoint, {
    		method: 'GET',
    		headers: {
    			Authorization: `Bearer ${resource.token}`,
    			'X-Restli-Protocol-Version': '2.0.0',
    			'LinkedIn-Version': `${resource.apiVersion}`
    		}
    	})
    
    	if (!response.ok) {
    		throw new Error(`HTTP error! status: ${response.status}`)
    	}
    
    	const data = await response.json()
    
    	return data
    }
    

    Submitted by hugo697 689 days ago