Hi @gvillasboas,
When the error message is "missing_scope", most probably the required scope is really missing. Is it so or not? 🤔 Do you have "sharing.write" scope within your scopes set declared for the application?
And something else: Why you are trying to use obsolete method in your code?! Despite such methods still work, they can get dropped at any time. Even more, why you are getting the same link twice? 🧐 I can't see a reason.
Hope this helps.
The 'missing_scope' error indicates that the app does not have the particular scope enabled for the app. Please check that you have the required scopes enabled on the permissions tab of the App console. Based on your code the correct scopes for CreateSharedLinkWithSettings requires sharing.write.
Also, be aware that just adding a scope to your app via the App Console does not retroactively grant that scope to existing access tokens. That being the case, to make any API calls that require that scope, you'll need to get a new access token with that scope.