As per this official Document :
If you get this error, do the following :
Make sure you've enabled the Pub/Sub API in the Google Cloud console.
Make sure that the principal making the request has the required permissions on the relevant Pub/Sub API resources, especially if you
are using Pub/Sub API for cross-project communication.
If you're using Dataflow, make sure that both {PROJECT_NUMBER}@cloudservices.gserviceaccount.com and the Compute
Engine Service account
{PROJECT_NUMBER}[email protected] have the
required permissions on the relevant Pub/Sub API resource. For more
information, see Dataflow Security and Permissions.
If you're using App Engine, check your project's Permissions page to see if an App Engine Service Account is listed as a Pub/Sub Editor. If it is not, add your App Engine Service Account as a Pub/Sub Editor. Normally, the App Engine Service Account is of the form <project-id>@appspot.gserviceaccount.com.
Refer to this document for more information and go through this stack link which might be helpful for you.