Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Acquire test user access tokens for integration tests #1084

Closed
zzvara opened this issue Aug 6, 2020 · 10 comments
Closed

Acquire test user access tokens for integration tests #1084

zzvara opened this issue Aug 6, 2020 · 10 comments
Assignees
Milestone

Comments

@zzvara
Copy link

zzvara commented Aug 6, 2020

Automated testing of integrations may require ad-hoc test users and access tokens created by parallel processes. Is there any support for test user generation and access token retrieval, and if not, do you plan to add these features?

@nbartels nbartels self-assigned this Aug 6, 2020
@nbartels
Copy link
Contributor

nbartels commented Aug 6, 2020

Yes, test users are supported. We have a special TestUser type for this and you can use RestFB to implement the calls described here: https://developers.facebook.com/docs/graph-api/reference/app/accounts/test-users#publish

If you need further information or example codes, please let me know.

@nbartels nbartels added this to the Unscheduled milestone Aug 6, 2020
@zzvara
Copy link
Author

zzvara commented Aug 7, 2020

@nbartels thank you for your kind response. Could you provide or point me to a schematic code snippet to start with? Do you have tests regarding this feature in restfb?

@nbartels
Copy link
Contributor

nbartels commented Aug 7, 2020

I'll push an integration test later on (today), so you can start with that.

@nbartels
Copy link
Contributor

nbartels commented Aug 7, 2020

Please check the commit, you should find the information to create and delete test users there.

@zzvara
Copy link
Author

zzvara commented Aug 7, 2020

@nbartels looks nice, I'm going to try it out ASAP!

@zzvara
Copy link
Author

zzvara commented Aug 8, 2020

I'm getting an exception:

Received Facebook error response of type OAuthException: Invalid OAuth access token. (code 190, subcode null) 'null - null'
com.restfb.exception.FacebookOAuthException: Received Facebook error response of type OAuthException: Invalid OAuth access token. (code 190, subcode null) 'null - null'
	at com.restfb.exception.generator.DefaultFacebookExceptionGenerator$DefaultGraphFacebookExceptionMapper.exceptionForTypeAndMessage(DefaultFacebookExceptionGenerator.java:174)
	at com.restfb.exception.generator.DefaultFacebookExceptionGenerator.throwFacebookResponseStatusExceptionIfNecessary(DefaultFacebookExceptionGenerator.java:61)
	at com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:794)
	at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:721)
	at com.restfb.DefaultFacebookClient.publish(DefaultFacebookClient.java:331)
	at com.restfb.DefaultFacebookClient.publish(DefaultFacebookClient.java:350)

This is how the client is created:

val client = new DefaultFacebookClient(secret, Version.LATEST)

And how publish is used:

    val accessToken = zuckerberg.client
      .publish(
        identifier + "/accounts/test-users",
        classOf[TestUser],
        Parameter.`with`("installed", true)
      ).getAccessToken

It seems to be working with calls like:

      val extendedAccessToken = client.obtainExtendedAccessToken(identifier, secret, accessToken)
      extendedAccessToken.getAccessToken

@nbartels
Copy link
Contributor

nbartels commented Aug 8, 2020

You need the app access token for this call: https://developers.facebook.com/docs/facebook-login/access-tokens/#apptokens

@zzvara
Copy link
Author

zzvara commented Aug 8, 2020

I can see it now, it works! Isn't this a bit confusing to use different keys for different use-cases with the same DefaultFacebookClient constructor waiting for an accessToken?

@nbartels
Copy link
Contributor

nbartels commented Aug 9, 2020

You may have several FacebookClient instances 😉

You could simply add the app access token facebook client in a base test class and create the testuser client in the Before method - as an example.

Facebook uses several access tokens and so we developer have to handle that ...

@zzvara
Copy link
Author

zzvara commented Aug 10, 2020

Facebook uses several access tokens and so we developer have to handle that ...

I see, thanks!

@zzvara zzvara closed this as completed Aug 10, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants