Posts tagged with curl

I'm using Python to create a script that allows me to create a label in the inbox (for a Facebook page), and then associate or tag a user with a specific label.

This is the function I made:

def associate_label_to_user(recipient_id, label_id, access_token): url = f"https://graph.facebook.com/v19.0/{label_id}/label?access_token={access_token}" data = {     "user": recipient_id } response = requests.post(url, json=data) response_json = response.json() # print(response_json) if response.status_code == 200:     success = response_json['success']     if success:         print("[LOGS] Association of label to user successful") else:     print("[LOGS] Error associating label to a user") 

I'm reading their documents here https://developers.facebook.com/docs/messenger-platform/identity/custom-labels/, and I'm not experiencing any other problem.

Whenever I run the script, it works (I see the user being labeled correctly), but I'm getting this error in return:

{'error': {'message': 'Unsupported request - method type: post', 'type': 'GraphMethodException', 'code': 100, 'fbtrace_id': 'ApHRHoVZFM_BUqHpOs3KdKX'}} 

I don't understand what this means, when it works for me anyway.

I'm having issues trying to download media files from the WhatsApp Business API. Following along with their documentation (https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media#download-media) they provide a cURL command that is successful in downloading a media file when used - however, the same request (I think) when done using NodeJS' fetch returns text/html responses with vague error wording and a 200 status code.

# Successful cURL: curl "https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=281274211304477&ext=1705672414&hash=ATtH6AOGFu0RqEpENicHUg8HCUkVfwGzfrHVCdiE7J8AUA" --header "Authorization: Bearer ..." 
// Successful cURL from child_process.exec: exec(   `curl --location "${mediaURL}" --header "Authorization: Bearer ..."` ); 
// Unsuccessful fetch: fetch(   "https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=281274211304477&ext=1705672414&hash=ATtH6AOGFu0RqEpENicHUg8HCUkVfwGzfrHVCdiE7J8AUA",   { headers: { Authorization: "Bearer ..." } } ); 

Suggestion from WhatsApp Cloud API Receiving Images from Users Error is also unsuccessful, unfortunately:

// Also unsuccessful fetch: fetch("https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=281274211304477&ext=1705672414&hash=ATtH6AOGFu0RqEpENicHUg8HCUkVfwGzfrHVCdiE7J8AUA", {   headers: {     Authorization: "Bearer ...",     "User-Agent": "curl/7.64.1",   }, }) 

Note: The lookaside.fbsbx.com URLs are all retrieved successfully from the WhatsApp Business APIs.

Per the documentation, a 404 error should occur if the link has expired, however, this isn't the case - and the access token hasn't expired either. Looking through the Community Forums, specifically https://developers.facebook.com/community/threads/1367000994138329/?join_id=f25971b6b4f9cc4, many conversations suggest that the User-Agent header should be spoofed - yet this doesn't seem to work either, although tweaking the User-Agent header within Postman yields varying results.

Successful in Postman:

Unsuccessful when User-Agent is adjusted in Postman:

Unsuccessful when User-Agent is removed in Postman:

Any suggestions would be greatly appreciated. I was unable to use the Meta for Developers' "Report a bug" forms as support appears to be unavailable for WhatsApp Business APIs.

Also seen posts: 1, 2 on StackOverflow; 1, 2, 3, 4, 5, 6 on Meta Support Forums.

I'm facing an error when creating a media template with sample image file. I'm following the developer facebook documentation: "https://developers.facebook.com/docs/whatsapp/business-management-api/message-templates/#message--media----interactive-templates" and the section is "Example Media Template Request".

I'm trying the following code.

My component code is :

[{"type":"header","format":"IMAGE","example":{"header_handle":["https://edailyshopping.com/images/download.jpg"]}},{"type":"body","text":"Wishing you all Ramadan Mubarak."}] 

API URL: https://graph.facebook.com/v16.0/{whatsapp-business-account-ID}/message_template

response is getting success.

**The problem is template is created but the sample media file is not uploaded. **

Can anyone any idea about it why the sample image is not uploaded?

I am Using Whatsapp Media API to get Image send from user to business number using webhooks and I also get the Image ID and URL and Image as well in Postman but when I use that curl request made from Postman it always shows Facebook error:

Sorry, something went wrong. We're working on it and we'll get it fixed as soon as we can.

But its working fine in Postman what am I doing wrong?

<?php $ua = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.16 (KHTML, like Gecko) \  Chrome/24.0.1304.0 Safari/537.16'; $curl = curl_init(); curl_setopt_array($curl, array(   CURLOPT_URL => 'Image_URL_from_Api',   CURLOPT_USERAGENT => $ua,   CURLOPT_RETURNTRANSFER => true,   CURLOPT_ENCODING => '',   CURLOPT_MAXREDIRS => 10,   CURLOPT_TIMEOUT => 0,   CURLOPT_FOLLOWLOCATION => true,   CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,   CURLOPT_CUSTOMREQUEST => 'GET',   CURLOPT_SSL_VERIFYPEER => false,   CURLOPT_HTTPHEADER => array(     'Authorization: Bearer My_Token'   ), )); $response = curl_exec($curl); curl_close($curl); echo $response; 

I try to make a keyword searches system for our employ and i have google ads developer token But I cannot able to find any CURL or PHP CURL setup guide.

Two reference links Ad API Examples
Method: customers.generateKeywordIdeas

An example from Google's documentation:

curl -f --request POST "https://googleads.googleapis.com/v${API_VERSION}/customers/${CUSTOMER_ID}/campaignBudgets:mutate" \ --header "Content-Type: application/json" \ --header "developer-token: ${DEVELOPER_TOKEN}" \ --header "login-customer-id: ${MANAGER_CUSTOMER_ID}" \ --header "Authorization: Bearer ${OAUTH2_ACCESS_TOKEN}" \ --data "{ 'operations': [   {     'create': {       'name': 'My Campaign Budget #${RANDOM}',       'amountMicros': 500000,     }   },   {     'create': {       'name': 'My Campaign Budget #${RANDOM}',       'amountMicros': 500000,     }   } ] }" 

I try this code but got Error

    <?          $ch = curl_init();          curl_setopt($ch, CURLOPT_URL, 'https://googleads.googleapis.com/v11/customers/(MANAGER_CUSTOMER_ID):generateKeywordIdeas');     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);     curl_setopt($ch, CURLOPT_POST, 1);     curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n\n\"keywordSeed\": {\n    \"keywords\": [\n    \"cofee\"\n  ]\n  }\n}");          $headers = array();     $headers[] = 'Content-Type: application/json';     $headers[] = 'Login-Customer-Id: (MANAGER_CUSTOMER_ID)';     $headers[] = 'Developer-Token: DEVELOPER_TOKEN';     $headers[] = 'Authorization: Bearer (OAUTH_ACCESS_TOKEN)';     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);          $result = curl_exec($ch);     if (curl_errno($ch)) {         echo 'Error:' . curl_error($ch);     }     print_r($result);     curl_close($ch); 

I'm not getting any output