TwitterOAuth PHP for v2 of the API (with OAuth 2) - php

The documentation on TwitterOAuthAPI.com leaves quite a bit to be desired, to say the least. However, the software does appear to work with an elevated Twitter API Developer account, when used with the API Key and Secret, along with the Access Token and Secret (passed into the TwitterOAuth constructor).
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret);
However, with an Essentials account, there's only access to OAuth 2, which Twitter seems to provide a Client ID and Client secret for. If I try to use the Access Token and Access Secret with an Essential account (not elevated or academic), it returns a status saying that an elevated account or academic account is required to use the v1 API).
The developer of TwitterOAuthAPI only currently has an honorable mention of v2 Twitter API and a small code segment, that seems to suggest all we have to do is
$connection->setApiVersion('2');
But this does not work. $connection->get no longer retrieves data, $connection->post no longer posts status updates - just a blank page from what I can tell (no errors or anything, just blank).
So I'm very confused as to how the Client ID and secret are used with this system as I assume, an alternative to the Access Token and Access Token Secret (?).
If anyone knows how to use TwitterOAuthAPI for PHP with the v2 of Twitter API and a non-elevated/academic account, I'd appreciate any insight.
Thanks for your time,
~G

Related

Google Calendar API - Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested

right now i'm using google-calendar-api with Laravel, i want to create a reminder, and let the user decides if he wants to shows it in his Google Calendar (based in his gmail account). Right now this code works fine:
I got an error when trying to add an attendee, Googling i found out that you need to "impersonate" the user you want to invite, so i tried the next approach:
And getting this error:
What do you guys think am i doing wrong?
In my Google Api Console i'm using a Service Account, i tried with several keys, i enabled Domain Wide Delegation:
Nothing works, as i said, i can create and list the events, but can't invite anyone.
Thanks in advance!
The error message
the client is not authorized to request a token using this method
Means that the client credetials that you created on Google developer console do not match the login method you are using
You apear to be using code designed for use with a service account
// Create and configure a new client object.
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope([YOUR SCOPES HERE]);
return $client;
To use this you need to create service account credentials on Google developer console. You have not.

How to go from PayPal permissions API Access Token to executing GetExpressCheckout

Using Angeleyes excellent Permissions tutorial and code, I have managed a small developer site, that can get Access Token and Token Secret. From there Im clueless, Paypals' Github claims a CreateInvoice sample, which doesnt exsist, and much searching i have learned(?).
You need to include your app credentials, your API username and API password, and in an added "SUBJECT" line the ... payer_ID merchant/payer email...
(conflicting info exsists here) to run another API you have permission to execute.
None of this is very clear for me. All tutorials end with the access code and Token secret.
I am attempting to add a buy now button that sources the MERCHANT from DB (multi merchant) but am getting nowhere overcoming this conceptual gap.
How do i mesh Permissions API with ExpressCheckout API? (step by step if possible)
Edit:
Search continues also, how does one recover from the permissions granting api methord the merchant email for subject?!
PayPal updated their description DURING the grant permissions screen, to mention Pal Id access..
Now going to open a new question, to find out how to use a saved Permissions Token and Secret in php to USE the access token and token secret to get pal ID.
hope this helps someone else :)

How to programmatically get the access token to send API call to Google Merchant Center (Google Shopping) with PHP?

I recently get in touch with Google merchant product to sync all my website products into Google Merchant. When I follow the structure of the API documentation https://developers.google.com/shopping-content/v2/quickstart
down to Authorization section I copy their library and copy the sample code to use. It actually work! However, when I doing testing to load that auth page it requires me to log in to the developer account for getting the access token and save it into session.
Is there any possibility that I can skip the login section to make it automatically then I can do corn system to run the sync (update products' details) hourly?
I tried to hardcore my account login API key into my code like this:
$client = new Google_Client();
$client->setApplicationName('Sample Content API application');
//add my api key here
$client->setDeveloperKey(MY_API_KEY);
$client->setClientId('YOUR_CLIENT_ID');
$client->setClientSecret('YOUR_CLIENT_SECRET');
$client->setRedirectUri('YOUR_REDIRECT_URI');
$client->setScopes('https://www.googleapis.com/auth/content');
But it doesn't workЖ шt still requires me to log in.
You want to use a service account for this.
The Google OAuth 2.0 system supports server-to-server interactions such as those between a web application and a Google service. For this scenario you need a service account, which is an account that belongs to your application instead of to an individual end user. Your application calls Google APIs on behalf of the service account, so users aren't directly involved. This scenario is sometimes called "two-legged OAuth," or "2LO." (The related term "three-legged OAuth" refers to scenarios in which your application calls Google APIs on behalf of end users, and in which user consent is sometimes required.)
Below is a working example of authentication via Service account with PHP.
PREREQUISITES
Install the "Content API for Shopping" library which you can download here. For installation see here.
Create your service account. Here you will find the complete procedure.
At this point you will have obtained your JSON file needed for authentication.
As suggested by Google:
Important: Protect the *.json key file that allows a service account
to access the Google services for which it has been authorized. It is
good practice to allow service accounts to only access one Google API
each. This is a preventative measure to mitigate the amount of data an
attacker can access in the situation that the service account’s *.json
key file is compromised.
You can now use the following function to get the access token for the API call:
// gets access token for API call to Google Merchant Center
function gets_access_token_for_API_call() {
// load the "Google APIs Client Library for PHP"
require_once ( '/path/to/google-api-php-client/vendor/autoload.php' );
// gets the JSON key of the service account
$credentialsFilePath = '/path/to/merchant-center-123456789-987654321.json';
$client = new Google_Client();
$client->setAuthConfig($credentialsFilePath);
$client->addScope( 'https://www.googleapis.com/auth/content' );
// fetches a fresh access token with a given assertion token.
$client->fetchAccessTokenWithAssertion(); // the deprecated alias: "refreshTokenWithAssertion()"
$token = $client->getAccessToken();
return $token;
}
The returned result will be an array similar to:
{
"access_token": "1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M",
"scope": "https://www.googleapis.com/auth/content"
"token_type": "Bearer",
"expires_in": 3600
}
The code has been tested and works.

Getting scores from Google Play Games Services, server side

I am trying to load from a web server some scores from GPGS, using the Google API PHP Client.
Here's how I proceed:
1/ SETTING UP THE OAUTH CLIENT
I created the OAuth client on the Google API Console using a service account, according this doc: https://developers.google.com/accounts/docs/OAuth2ServiceAccount
It provided me a certificate + an email address + a client_id.
2/ WRITING PHP CODE
Here's my code:
$client = new Google_Client();
$client->setApplicationName("");
$client->setAssertionCredentials(
new Google_Auth_AssertionCredentials(
"something#developer.gserviceaccount.com", // email provided by console
array('https://www.googleapis.com/auth/games'), // scope
file_get_contents("../certificates/certificate.p12") // keyfile i downloaded
)
);
$service = new Google_Service_Games($client);
$service->scores->listScores("myLeaderboardId", "PUBLIC", "ALL_TIME");
3/ FIRST RESULTS
The first weird thing about this snippet, is that the API thrown me an error with an HTTP status 401 with this message:
Request was missing required scope(s): plus.login
According the official documentation (https://developers.google.com/games/services/web/api/scores/list) the required scope for this request is only games
4/ HITTING A WALL
Adding this scope to my request was really not a big deal, but after that, the API responded me again with a 401 HTTP status:
User has not completed registration
which I completly understand, since I am using credentials from a service account, and not a real account.
QUESTION
What am I doing wrong? Do I really can load leaderboards by calling the Google API from a server?
Thanks in advance for helping me,
Regards,

twitter rest api v 1.1 in flash application + php

First, I've create a app twitter and read the documentation that the rest api v1.0 will not supported(available) longer and the new one is v1.1
Then, I've develop a flash app that utilize twitter by retrieve user's profile and that profile will be the base for data comparison process.
How I can build a sign-in twitter mechanism so when the user succesfully sign-in the apps get the profile data and will do some comparison mechanism? Is ther any tutorial about this especially work around with twitter rest api v1.1?
And what about consumer key, consumer secret, Access token secret, Access token?
Sorry if ask a lot questions because some tutorial I found in internet not work properly.
So far I have only found the following library in github.com, but yet to decipher the usage of the library:
https://github.com/susisu/Twitter-for-AS3

Categories