From be1f1c847d9bb2d43a4bfc2b2b321a96f11c5a00 Mon Sep 17 00:00:00 2001 From: Florent Ravenel Date: Sat, 26 Aug 2023 18:00:33 +0200 Subject: [PATCH] feat: rename notebook and update variables --- ...nteractions_from_post_URL_to_HubSpot.ipynb | 241 ----------- ...tions_from_post_URL_to_HubSpot_notes.ipynb | 376 ++++++++++++++++++ 2 files changed, 376 insertions(+), 241 deletions(-) delete mode 100644 LinkedIn/LinkedIn_Send_interactions_from_post_URL_to_HubSpot.ipynb create mode 100644 LinkedIn/LinkedIn_Send_interactions_from_post_URL_to_HubSpot_notes.ipynb diff --git a/LinkedIn/LinkedIn_Send_interactions_from_post_URL_to_HubSpot.ipynb b/LinkedIn/LinkedIn_Send_interactions_from_post_URL_to_HubSpot.ipynb deleted file mode 100644 index e91be08041..0000000000 --- a/LinkedIn/LinkedIn_Send_interactions_from_post_URL_to_HubSpot.ipynb +++ /dev/null @@ -1,241 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "639722ac-17b0-4a4e-bc38-0b409b9516bc", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "\"Naas\"" - ] - }, - { - "cell_type": "markdown", - "id": "40ed2bcf-6795-4c72-9d82-c6cd3d237fb8", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "# LinkedIn - Send interactions from post URL to HubSpot" - ] - }, - { - "cell_type": "markdown", - "id": "a12a1d93-048d-4c1b-aa81-3a362a8bf6dc", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "**Tags:** #linkedin #hubspot #interactions #post #url #send" - ] - }, - { - "cell_type": "markdown", - "id": "5cc3f1bb-5f08-493e-8463-16a4973fb09a", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel)" - ] - }, - { - "cell_type": "markdown", - "id": "33ab1d7c-8784-43a4-960e-96b2be7451e7", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "**Last update:** 2023-08-16 (Created: 2023-08-16)" - ] - }, - { - "cell_type": "markdown", - "id": "bd8105de-e723-4453-b974-846308cc7b89", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "**Description:** This notebook automates the process of sending interactions from a LinkedIn post URL to HubSpot. It is usefull for organizations that need to track the performance of their LinkedIn posts." - ] - }, - { - "cell_type": "markdown", - "id": "8f969c04-e91b-4db4-be41-9523ccd314c2", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "**References:**\n- [LinkedIn API Documentation](https://docs.microsoft.com/en-us/linkedin/shared/references/v2/profile/shares?context=linkedin/consumer/context)\n- [HubSpot API Documentation](https://developers.hubspot.com/docs/methods/social-media/get-all-social-media-posts)" - ] - }, - { - "cell_type": "markdown", - "id": "bc30bcf2-57e6-48ae-a7c5-6218a7798182", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "## Input" - ] - }, - { - "cell_type": "markdown", - "id": "e2661a6b-1c2c-488f-9c8e-bb2523197155", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "### Import libraries" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "93ee3f31-b14b-494c-863b-8a31ca93ca50", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": "import requests\nimport json", - "outputs": [] - }, - { - "cell_type": "markdown", - "id": "c368f87c-f929-4212-bf17-2dfd537b9c54", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "### Setup variables\n- `linkedin_post_url`: URL of the LinkedIn post\n- `hubspot_api_key`: API key of the HubSpot account" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2c1ee8c1-e150-4465-b4fe-c3768f397d84", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": "linkedin_post_url = \"https://www.linkedin.com/posts/example_post\"\nhubspot_api_key = \"123456789\"", - "outputs": [] - }, - { - "cell_type": "markdown", - "id": "0c8d1e9c-da8b-4526-be0c-67cfde63ebf0", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "## Model" - ] - }, - { - "cell_type": "markdown", - "id": "78faee51-7f88-4c9c-b805-2a021be02424", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "### Get interactions from LinkedIn post" - ] - }, - { - "cell_type": "markdown", - "id": "385db19a-ded1-4b83-8195-79f2db9053a8", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "Retrieve the interactions from a LinkedIn post URL using the LinkedIn API." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "a07db68f-38ff-4723-bb73-93cc4bd84a5f", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": "# Get interactions from LinkedIn post\nresponse = requests.get(\n f\"https://api.linkedin.com/v2/shares?q=shareUrls&url={linkedin_post_url}\"\n)\n# Parse response\ninteractions = json.loads(response.text)", - "outputs": [] - }, - { - "cell_type": "markdown", - "id": "9782fe0b-7d61-4f67-b18e-61c782c28eb2", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "## Output" - ] - }, - { - "cell_type": "markdown", - "id": "6f854789-dbc2-4aab-95bf-a53eaa447d75", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "### Display result" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "0b5fa4d1-cacd-45f5-b542-c78e6a36366c", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": "# Print interactions\nprint(interactions)", - "outputs": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.6" - }, - "widgets": { - "application/vnd.jupyter.widget-state+json": { - "state": {}, - "version_major": 2, - "version_minor": 0 - } - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} \ No newline at end of file diff --git a/LinkedIn/LinkedIn_Send_interactions_from_post_URL_to_HubSpot_notes.ipynb b/LinkedIn/LinkedIn_Send_interactions_from_post_URL_to_HubSpot_notes.ipynb new file mode 100644 index 0000000000..5b8de47aa3 --- /dev/null +++ b/LinkedIn/LinkedIn_Send_interactions_from_post_URL_to_HubSpot_notes.ipynb @@ -0,0 +1,376 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "639722ac-17b0-4a4e-bc38-0b409b9516bc", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\"Naas\"" + ] + }, + { + "cell_type": "markdown", + "id": "40ed2bcf-6795-4c72-9d82-c6cd3d237fb8", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# LinkedIn - Send interactions from post URL to HubSpot notes" + ] + }, + { + "cell_type": "markdown", + "id": "a12a1d93-048d-4c1b-aa81-3a362a8bf6dc", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #linkedin #hubspot #interactions #post #url #send #notes" + ] + }, + { + "cell_type": "markdown", + "id": "5cc3f1bb-5f08-493e-8463-16a4973fb09a", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel)" + ] + }, + { + "cell_type": "markdown", + "id": "33ab1d7c-8784-43a4-960e-96b2be7451e7", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2023-08-16 (Created: 2023-08-16)" + ] + }, + { + "cell_type": "markdown", + "id": "bd8105de-e723-4453-b974-846308cc7b89", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Description:** This notebook automates the process of sending people interactions (like or comment) on a LinkedIn post URL to a contact notes in HubSpot. If the people does not exist in HubSpot, she/he will be created." + ] + }, + { + "cell_type": "markdown", + "id": "8a81d778-e5e9-437b-a7c9-38d84a08b7d4", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\n", + "
\n", + "Disclaimer:
\n", + "This code is in no way affiliated with, authorized, maintained, sponsored or endorsed by Linkedin or any of its affiliates or subsidiaries. It uses an independent and unofficial API. Use at your own risk.\n", + "\n", + "This project violates Linkedin's User Agreement Section 8.2, and because of this, Linkedin may (and will) temporarily or permanently ban your account. We are not responsible for your account being banned.\n", + "
\n", + "
" + ] + }, + { + "cell_type": "markdown", + "id": "bc30bcf2-57e6-48ae-a7c5-6218a7798182", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "e2661a6b-1c2c-488f-9c8e-bb2523197155", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "93ee3f31-b14b-494c-863b-8a31ca93ca50", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "import naas\n", + "from naas_drivers import linkedin, hubspot\n", + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "id": "c368f87c-f929-4212-bf17-2dfd537b9c54", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables\n", + "**Mandatory**\n", + "\n", + "[Learn how to get your cookies on LinkedIn](https://www.notion.so/LinkedIn-driver-Get-your-cookies-d20a8e7e508e42af8a5b52e33f3dba75)\n", + "- `li_at`: Cookie used to authenticate Members and API clients.\n", + "- `JSESSIONID`: Cookie used for Cross Site Request Forgery (CSRF) protection and URL signature validation.\n", + "- `linkedin_url`: This variable represents the LinkedIn profile URL.\n", + "\n", + "[Get your HubSpot Access token](https://knowledge.hubspot.com/articles/kcs_article/integrations/how-do-i-get-my-hubspot-api-key)\n", + "- `hs_access_token`: This variable stores an access token used for accessing the HubSpot API.\n", + "\n", + "**Optional**\n", + "- `properties`: List of properties (hubspot internal names) you want to get from contact. By default, you will get: email, firstname, lastname, createdate, lastmodifieddate, hs_object_id. To list of contact properties, you can use this template: \"HubSpot/HubSpot_List_contact_properties.ipynb\" stored in https://github.com/jupyter-naas/awesome-notebooks." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2c1ee8c1-e150-4465-b4fe-c3768f397d84", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "# Mandatory\n", + "li_at = naas.secret.get(\"LINKEDIN_LI_AT\") or \"YOUR_LINKEDIN_LI_AT\" #example: AQFAzQN_PLPR4wAAAXc-FCKmgiMit5FLdY1af3-2\n", + "JSESSIONID = naas.secret.get(\"LINKEDIN_JSESSIONID\") or \"YOUR_LINKEDIN_JSESSIONID\" #example: ajax:8379907400220387585\n", + "linkedin_url = \"https://www.linkedin.com/feed/update/urn:li:activity:7100209398274220032\" # EXAMPLE \"https://www.linkedin.com/in/XXXXXX/\"\n", + "hs_access_token = naas.secret.get(\"HS_ACCESS_TOKEN\") or \"YOUR_HS_ACCESS_TOKEN\"\n", + "\n", + "# Optional\n", + "properties = []" + ] + }, + { + "cell_type": "markdown", + "id": "0c8d1e9c-da8b-4526-be0c-67cfde63ebf0", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "7a4577bb-55bb-4b62-be75-417458f7ae47", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Get post likes" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "24f61a77-74aa-410e-a3e8-f29ed8eae762", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "df_likes = linkedin.connect(li_at, JSESSIONID).post.get_likes(linkedin_url)\n", + "print(\"Number of likes: \", len(df_likes))\n", + "df_likes.head(5)" + ] + }, + { + "cell_type": "markdown", + "id": "cc2e5514-20d6-4f8d-94aa-6a8dbf714a17", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Get post comments" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "42cf7ffb-a788-4ab6-9d8e-5b5d1b66cf7a", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "df_comments = linkedin.connect(li_at, JSESSIONID).post.get_comments(linkedin_url)\n", + "print(\"Number of comments: \", len(df_comments))\n", + "df_comments.head(5)" + ] + }, + { + "cell_type": "markdown", + "id": "c2f44181-36df-415e-b580-d14bea3764f1", + "metadata": { + "execution": { + "iopub.execute_input": "2023-08-25T14:08:32.133288Z", + "iopub.status.busy": "2023-08-25T14:08:32.133052Z", + "iopub.status.idle": "2023-08-25T14:08:32.136213Z", + "shell.execute_reply": "2023-08-25T14:08:32.135544Z", + "shell.execute_reply.started": "2023-08-25T14:08:32.133264Z" + }, + "tags": [] + }, + "source": [ + "### Create database of LinkedIn profiles" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d23cbbb8-d794-43a1-8e28-de46b855ae8d", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "def create_profiles_db(\n", + " df_likes,\n", + " df_comments\n", + "):\n", + " # Init\n", + " df = pd.DataFrame()\n", + " \n", + " # Concat db\n", + " to_keep = [\n", + " \"PROFILE_ID\",\n", + " \"PROFILE_URL\",\n", + " \"PUBLIC_ID\",\n", + " \"FIRSTNAME\",\n", + " \"LASTNAME\",\n", + " \"FULLNAME\",\n", + " \"OCCUPATION\",\n", + " \"PROFILE_PICTURE\",\n", + " ]\n", + " df = pd.concat([df_likes, df_comments])[to_keep].drop_duplicates(to_keep)\n", + " return df.reset_index(drop=True)\n", + "\n", + "df_profiles = create_profiles_db(\n", + " df_likes,\n", + " df_comments\n", + ")\n", + "print(\"LinkedIn profiles:\", len(df_profiles))\n", + "df_profiles.head(5)" + ] + }, + { + "cell_type": "markdown", + "id": "4d3aa77d-0319-4d5a-a26d-3dd83aae0046", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Get all contacts" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "47a2c33b-e563-4852-a6eb-519fb84eb170", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "df_contacts = hubspot.connect(hs_access_token).contacts.get_all(properties)\n", + "print(\"Rows:\", len(df_contacts))\n", + "df_contacts.head(1)" + ] + }, + { + "cell_type": "markdown", + "id": "9782fe0b-7d61-4f67-b18e-61c782c28eb2", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "6f854789-dbc2-4aab-95bf-a53eaa447d75", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Display result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0b5fa4d1-cacd-45f5-b542-c78e6a36366c", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "# Print interactions\n", + "print(interactions)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.6" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}