auto create a FB QR code and save image to a folder

Can someone please help me I wan’t to auto create a FB QR code and save image to a folder. Have read this from FB developers page but have no idea implementing it in a php script

https://developers.facebook.com/docs/messenger-platform/discovery/messenger-codes

Generating a parametric code :-

curl -X POST -H “Content-Type: application/json” -d ‘{
“type”: “standard”,
“data”: {
“ref”:“billboard-ad”
},
“image_size”: 300
}’ “https://graph.facebook.com/v2.6/me/messenger_codes?access_token=<ACCESS_TOKEN>”

and api response:-

{
“uri”: “<YOUR_CODE_URL_HERE>”
}

hi,

You can use file_get_contents like this
[php]<?php
$token = ‘xxxx’;
$url = “https://graph.facebook.com/v2.6/me/messenger_codes?access_token=” . $token;

$request = ‘{
“type”: “standard”,
“data”: {
“ref”:“billboard-ad”
},
“image_size”: 300
}’;

$context = stream_context_create([
‘http’ => [
‘method’ => ‘POST’,
‘header’ => ‘Content-Type: application/json’,
‘content’ => $request,
‘ignore_errors’ => true,
],
]);

$result = file_get_contents($url, false, $context);
$parsed = json_decode($result, true);

print_r($parsed);[/php]

I have no valid tokens so I got this: [code]Array
(
[error] => Array
(
[message] => Invalid OAuth access token.
[type] => OAuthException
[code] => 190
[fbtrace_id] => A6VwizTy8KL
)

)[/code]

and when you have QR-image url you can save it into any place you want
[php]$imagefrom = ‘https://facebook/…’;
$imageto = ‘/my/local/dir/image.png’;

$source = fopen($imagefrom, ‘r’);
$dest = fopen($imageto, ‘w’);

stream_copy_to_stream($source, $dest);

fclose($source);
fclose($dest);[/php]

With my access token inserted I receive following error when opening the page

Array ( [error] => Array ( [message] => Unsupported post request. Object with ID ‘me’ does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api [type] => GraphMethodException => 100 [error_subcode] => 33 [fbtrace_id] => AWRQ8U+EcMl ) )

Sponsor our Newsletter | Privacy Policy | Terms of Service