This could be due to the setting within SharePoint that is set by default to block scripts from running, which causes Access Denied errors when trying to add Custom Actions using ScriptLink as the location. I followed the same sample as you did and received the same Access Denied error. The good news is that this can be set to Allow, which fixed it for me. You can go into your Office 365 account, then Admin, then Sharepoint Admin. Go to Settings and find the section called Custom Script and choose Allow users to run custom script on self-service created sites. You can allow it for Personal Sites too if you want.
However, this change can take up to 24 hours, and I wanted to test it right away. So I referenced this page and I ran the following commands via SP PowerShell:
You should see the following output:
cmdlet Connect-SPOService at command pipeline position 1
Supply values for the following parameters:
Input your admin url for your sharepoint site, so if your site is
https://mysite.sharepoint.com then you would type
https://mysite-admin.sharepoint.com It will then prompt you to login. After you login, it should take you back to the PS prompt. Now use the following command:
Set-SPOsite "https://mysite.sharepoint.com" -DenyAddAndCustomizePages 0
It took 10 seconds or a little more for me for it to make the change. Then I tried my code again and it worked! I hope it does for you too!