-
Register/login for digikey API: https://developer.digikey.com/
-
Go to organizations tab:
(we're going to skip making a sandbox version of the app)
-
Create new organization
-
Click Production Apps next to your new organization
-
Create Production App
-
Fill in the details, paying special attention to the following:
-
Name - doesn't matter
-
OAuth Callback -
https://localhost
-
Description - doesn't matter
-
Select at least the following:
-
-
Click add production app
-
Next screen should look like what's shown below. Click the app name (circled)
-
Open the
barcode_scan.py
file in a text editor and copy and paste the your Client ID (BBB
) and Client Secret (CCC
) from your app credentials into their respective fields:(note: you wont have a value for
code
yet)app_credentials= { 'code': 'AAA', 'client_id': "BBB", 'client_secret': "CCC", 'mouser_key': "DDD" }
-
Now ensure you have the necessary python3 libraries:
Windows Powershell, Linux, & MacOS:
pip3 install pyzbar, pylibmtx, opencv-python
and if you want to use a webcam to scan barcodes:
pip3 install opencv-python
(note: your system may use
pip
instead ofpip3
. Either way, just make sure you're installing python3 packages) -
Save and run the
barcode_scan.py
file using python3 and you will get an error message.Windows Powershell:
PS C:\Users\USER\DEMO_DIRECTORY> python barcode_scan.py
Linux/MacOS
USER@DESKTOP:~/DEMO_DIRECTORY$ python barcode_scan.py
The error message should look similar to the one below, otherwise, troubleshoot the errors and try again.
-
With a similar error message as shown above, proceed by copying the URL underlined in red.
-
Open a new tab in your browser and paste the previously copied URL
-
You should be directed to a page that looks like this (you may need to log in). Click "Allow"
-
Paste the copied code into the
barcode_scan.py
file replacing theAAA
term:app_credentials= { 'code': 'AAA', 'client_id': "BBB", 'client_secret': "CCC", 'mouser_key': "DDD" }
-
After updating the 3
app_credential
fields, save thebarcode_scan.py
file and run again.(note: the OAuth code is only good for 60 seconds. If you get an error saying the code expired, just navigate to the URL again and repeat the process)
-
A the first successful
barcode_scan.py
should look like this when starting:Running subsequent
barcode_scan.py
(after the first successful startup) will look like this:(you shouldn't need to do the OAuth code any longer)
-
If you have a webcam the example script will try and connect.
-
To return detailed product information, change
product_info=False
toproduct_info=True
.
Mouser's API is easier to set up but much more limited in its capability.
-
Navigate to https://www.mouser.com/MyMouser/MouserSearchApplication.aspx and register for an API account
-
You'll recieve an email shortly containing an "API Key."
-
Enter the API key into the
DDD
field in barcode_scan.py:app_credentials= { 'code': 'AAA', 'client_id': "BBB", 'client_secret': "CCC", 'mouser_key': "DDD" }