OAuthException: An unexpected error has occurred - after changing app namespace - php

we had a working facebook app with an own action that has been reviewed and been approved by facebook. Everything worked fine.
After changing the namespace and the title of the app, we now get an an error when sending the action via php sdk, althought all the action is still marked as approved and live.
$response = $facebook->api(
'me/myapp:create',
'POST', array('custom_object' => "http://www.myapp.com/metatags.php") );
This is the error we receive:
OAuthException: An unexpected error has occurred. Please retry your request later.
We've' already checked if the access token is vaild, it is!
Is it possible that facebook needs to re-approve custom actions after changing the namespace? Or does it need some time until it works again?

I dealt with this today, however my experience was in JavaScript, so I don't have relevant code to provide, you should be able to apply the same theory!
It seems that the error only happens once per access request - if you try to post again immediately after, it will usually be accepted by facebook with no error. Since the error code returned for unknown error is always the same, you can simply catch the error code from the response object and run the function again if it matches.

Related

Yii2 OpenId Connect error - yii2-authclient returns 400 error "Token not provided" when I try to getUserAttributes()

I'm implementing OpenId Connect into my Yii2 app using the yii2-authclient library. I can login and exchange the code for a token with no problems. I've followed most of the code examples on the web and set a successCallback function that gets called once a user successfully logs in. It looks like this:
public function successCallback(ClientInterface $client)
{
$attributes = $client->getUserAttributes();
}
This code gets called, but calling getUserAttributes() results in the following error:
Exception – yii\authclient\InvalidResponseException
Request failed with code: 400, message:
{"error":"invalid_request","error_description":"Token not provided"}
The logs on the id server show a blank client and user, with an error of invalid_token.
I took a close look at the request I make and I see an access_token element. Any ideas what the problem might be? I can provide more information if necessary.
I figured it out. The problem was that the yii2-authclient library was sending the token as a GET parameter and the ID server was expecting it as a POST param. I upgraded the yii2-authclient library and that solved the problem since a recent change sends the parameter as POST instead of GET.

Access Youtube channels from oauth'd user

I'm trying to get all channels and eventually all videos for the user logged into my site with Google. I'm using Laravel Socialite to set the scope that I think should give the proper permissions. I'm then setting the access token to the session.
public function loginGoogle()
{
return Socialite::driver('google')->setScopes(['https://www.googleapis.com/auth/youtube.readonly',])->redirect();
}
When handling the call back after authenticating the user and saving the access token I run the following:
dd(\Youtube::getService()->channels->listChannels('snippet', ['managedByMe' => true, 'onBehalfOfContentOwner' => session('access_token')]));
\Youtube is just the facade I made to handle Youtube functionality in my site.
When running the code the following error is thrown:
Client error: `GET https://www.googleapis.com/plus/v1/people/me?prettyPrint=false` resulted in a `403 Forbidden` response:
{"error":{"errors":[{"domain":"global","reason":"insufficientPermissions","message":"Insufficient Permission"}],"code":4 (truncated...)
I can't tell if I'm using the incorrect scope or just messing something bigger up. Youtube's documentation hasn't been very helpful in this. They just say the user has to be authorized which...they are?
Been a couple days on this and am not sure where to go next.
Changing
return Socialite::driver('google')->setScopes(['https://www.googleapis.com/auth/youtube.readonly',])->redirect();
to
return Socialite::driver('google')->scopes(['https://www.googleapis.com/auth/youtube.readonly',])->redirect();
seemed to fix it. Looking at the documentation it makes sense why that wouldn't work.

Google Analytics API login required error

I've got a strange problem that I've tried to solve but I've tried a whole day and it just doesn't work, so I hope maybe someone else can help me with this.
I've build a CMS and after you login you see the dashboard.
On this dashboard you can click on a button to connect your account with Google - because I want my customers to be able to connect their Google Analytics account.
Everything works fine, I've got tokens and the refresh token and everything seems to work. Even when I request my user profile data I get it printed on my screen as an array. But when I try to get the accounts that are available to view for the connected user i get this error:
Uncaught exception 'Google_Service_Exception' with message 'Error calling GET
https://www.googleapis.com/analytics/v3/management/accounts/~all/webproperties
key=xxxxxxxxxxxxxxxxxxxxxxxxxx: (401) Login Required'
I just don't understand why I get the message 'Login required'.
Below you can see my script.
require_once('/Google/Client.php');
require_once('/Google/Service/Analytics.php');
// call object
$client = new Google_Client();
$client->setApplicationName("Google Analytics - CMS title");
$client->setClientId('xxxxxxxxxxxxxxxxx');
$client->setClientSecret('xxxxxxxxxxxxxxxx');
$client->setRedirectUri('xxxxxxxxxxxxxxxxxxx');
$client->setDeveloperKey('xxxxxxxxxxxxxxxxxxx');
$client->setApprovalPrompt('auto');
$client->setAccessType('offline');
$client->setScopes(array(
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/analytics'
));
// decode
$token = $token; // this comes from my database and it's json encoded
// connect
$client->setAccessToken($token);
// call service
$service = new Google_Service_Analytics($client);
// get accounts from analytics
$accounts = $service->management_accounts->listManagementAccounts();
When I try to var_dump $accounts I don't see anything because the error already occurred (Login required)
I think you are going to ask me now if my token is correct but it is because I tested it with other api calls.. it's just not working for this specific analytics request.
I hope someone can help me with this.
Thanks,
Pim vd Molen
UPDATE:
Something really strange just happened. I don't know how this is possible but the error just changed into another error:
Uncaught exception 'Google_Service_Exception' with message 'Error calling GET
https://www.googleapis.com/analytics/v3/management
/accounts?key=xxxxxxxxxxxxxxxxxx: (403) Access Not Configured.
Please use Google Developers Console to activate the API for your project.
I've enabled the Google Analytics service ofcourse, but don't know which one i also need to enable.
The 401 error clearly states that the credentials are wrong. The Token might be valid for retrieving Data, but for retrieving user management information, you need a particular grant when asking for that token, please look here in the table you see the additional value for the scope parameter to set in your OAuth request.
not sure if you have solved this yet, but I've documented the process, with photos here:
https://circlical.squarespace.com/blog/2014/7/18/getting-zend-framework-2-and-googles-api-to-play-nice

Facebook application error- Access Token

I have made new Facebook application, and when I am trying to allow "post to profile", I am getting this error:
Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown in /home/mimota/public_html/gamingapp.com/test/src/base_facebook.php on line 1024
Thats part of the base_facebook.php file:
http://codeviewer.org/view/code:2263
I have marked there where is line 1024
I will really appriciate if some one could figure out whats wrong here, because I have no clue..
Thanks.
Use a URL of the following format to log into facebook:
https://graph.facebook.com/oauth/authorize?client_id=288229791195831&redirect_uri=http://www.facebook.com/connect/login_success.html&type=user_agent&display=popup&scope=publish_stream,user_photos,read_stream,email
They will give you a token back which you will use when you send requests:
For example to see get the main photo URL use:
https://graph.facebook.com/me/picture&access_token=THE_TOKEN_YOU_GOT_BACK
To post to wall replace /me/picture with whatever you need to post (sth like /me/wall)

Can't get "Live Delegated Authentication" to work

I try to get the Live Delegated Authentication to work for the purpose of reading the email addresses.
I am doing this in PHP with the help of the windowslivelogin library. The problem is that I get an error.
I'm not sure what I'm doing wrong, i registered my application on the Azure webpage and got the appid and the secret into the code. This is what i use to initialize the Live Library :
$o = new WindowsLiveLogin();
$o->setAppId('000000004801B670');
$o->setSecret('secret');
$o->setSecurityAlgorithm('wsignin1.0');
$o->setDebug(true);
$o->setPolicyUrl('http://www.google.com/aides.html');
$o->setReturnUrl("http://michaelp.dev.gamepoint.net/framework/mainsite/contactimporter/?service=live");
return $o;
Then I call
$this->LiveLibrary->getLoginUrl()
And after I Login in to Live, it posts 2 things back, $_POST['stoken'] and $_POST['action'].
As soon as I call
$this->LiveLibrary->processLogin($_REQUEST);
It fails and gives back an error that the token is invalid.
I tried getting Consent straight away by making redirecting to
$this->LiveLibrary->getConsentUrl("Contacts.View");
But that gives an 3007 error and says that it cant share the information
According to MS this means the following :
3007
Consent Service API failed in the <method name> method. The application verifier is invalid.
The offer security level requires that a valid application verifier be passed with the request.
I am using the following URL, generated by the library
https://consent.live.com/Delegation.aspx?ps=Contacts.Invite&ru=http%3A%2F%2Fmichaelp.dev.gamepoint.net%2Fframework%2Fmainsite%2Fcontactimporter%2F%3Fservice%3Dlive&pl=http%3A%2F%2Fwww.google.com%2Faides.html&app=appid%3D000000004801B670%26ts%3D1251722931%26sig%3DD2gkM%252F%252FwlRXXfS64NMrV%252Bkt50v6dAOcESblfRk7j%252FUE%253D
I don't understand most of the documentation Microsoft has on this thing, I think its really unclear and chaotic. Also the Sample I tried doesn't work. I get an error message, it can't validate/decode the token. Same I get when I try the processLogin().
Thanks in Advance,
Michael

Categories