I am able to get the Records of the UserVoice by calling and Unauthorized Requests but now i want to create and Update things in which i need OAuth but i am unable to find the UserVoice's PHP Implementation of OAuth and Create/Update/Delete with UserVoice API is there anyone can guide me how to Implement such thing??
We have quite recently worked on this and released an OAuth-based library which makes it a bit easier to access UserVoice API from a PHP version 5 application.
An example on how to create a ticket using an access token for user#example.com:
<?php
require_once('vendor/autoload.php'); // Using Composer
$client = new \UserVoice\Client('subdomain-name', 'API KEY', 'API SECRET');
$access_token = $client->login_as('user#example.com');
$result = $access_token->post("/api/v1/tickets", array(
'ticket' => array(
'state' => 'open',
'subject' => 'PHP SDK',
'message' => "Would you have any OAuth example for PHP?"
)
));
?>
Despite the fact that the library is still under development, I believe it's already useful to you. See the blog post and more examples like responding to tickets as an account owner at:
http://developer.uservoice.com/docs/api/php-sdk/
Related
I'd like to create a small dashboard containing some analytics data from my mobile application. I found the new Google Analytics Data API which would be perfect for that. I want to run reports in my backend PHP application, so I'm using the PHP client library: https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/analyticsdata
Unfortunately I keep running against a 400 error on oauth2.
These are the steps I've done so far:
I've migrated my Firebase project to use a Google Analytics 4
property
Followed the steps in the guide of the client library for PHP
Registered & enabled the API for my project
Add credentials:
Using Google Analytics Data API
Using web server
Accessing application data
This results in a message saying an active service account already qualifies
For that service account I created a new key and downloaded the .json file
Added the client_email field as a user to my Google Analytics property with read access
In my PHP projects I installed the necessary dependencies and added the credentials .json file and copied the sample code:
$kernel = $this->getConfigurationPool()->getContainer()->get('kernel');
$path = $kernel->locateResource('#ApplicationBundle/Resources/config/credentials.json');
$property_id = '123456789';
$credentials_json_path = $path;
$client = new BetaAnalyticsDataClient(['credentials' =>
$credentials_json_path]);
// Make an API call.
$response = $client->runReport([
'property' => 'properties/' . $property_id,
'dateRanges' => [
new DateRange([
'start_date' => '2020-03-31',
'end_date' => 'today',
]),
],
'metrics' => [new Metric(
[
'name' => 'activeUsers',
])
]
]);
This results in a 400 bad request on https://oauth2.googleapis.com/token with the following response:
{"error":"invalid_scope","error_description":"Invalid OAuth scope or ID token audience provided."}
Which seems weird since it's supposed to use the service account no? I think I followed all the steps from the docs. Did I miss something?
Thanks in advance.
I'm trying to connect to AdSense API using a PHP script.
I started using this tutorial by google: https://developers.google.com/api-client-library/php/start/get_started#build-the-client-object
However, I didn't manage to connect. This is what I've tried:
$client = new Google_Client();
$client->setApplicationName("AppName");
$client->setDeveloperKey(API_Key);
$client->setAuthConfigFile('../AdSense/google-api-php-client/client_secret.json');
$service = new Google_Service_AdSenseTest($client);
$results = $service->testReportsGenerate();
foreach($results as $item)
{
echo $item;
}
And I came across a few problems, the main one is that the code doesn't recognize the "Google_Service_AdSenseTest" class - even though the code suggested it.
So my real question is this: What service should I use if I want to pull data from AdSense? And how do I set the needed parameters (meaning - which dimensions and metrics to get)?
Thank you.
You need to implement OAuth requests as you do for every single google api, (use Phil Sturgeon's OAuth2.0 protocol if you use codeigniter, well implemented.) or any oauth2 client scripts will do.
The google api library is here : https://github.com/googleapis/google-api-php-client-services. Use composer to install these libraries.
The adsense class is here : https://github.com/googleapis/google-api-php-client-services/blob/master/src/Google/Service/AdSense.php
The class/function which makes the request to google must setup an oauth client and specify a redirect url (which in turn must be registered on google api console )
The scopes are
../auth/adsense
../auth/adsense.readonly
Once everything is done, you can make a request.
I implemented it with Codeigniter for searchconsole, adsense and other useful libraries they all works awesome. Besides i connected google sheets as well, so every report is available to me in google sheet as it is needed.
With oAuth Access token, The code :
$client = new Google_Client();
$adsenseService = new Google_Service_AdSense(...);
$client->setApplicationName("Adsense Console");
$client->setDeveloperKey($apiKey);
$client->setAccessToken( $token->access_token );
$params = array('maxResults' => 1000, 'pageToken' => null, 'alt' => 'json', 'fields' => array(), 'prettyPrint' => true, 'quotaUser' => '', 'userIp' => '' );
$accounts = $adsenseService->accounts->listAccounts($params);
//this will print a json array
echo '<pre>' ; print_r($accounts); echo '<pre>'; die();
for adclients,
$adsense->adclients->listAccountsAdclients($params);
The params ref is here,
https://developers.google.com/adsense/management/v1.4/reference/accounts/adclients/list#try-it
you could try the example from https://github.com/googleads/googleads-adsense-examples/tree/master/php-clientlib-1.x/v1.x
More info at https://developers.google.com/adsense/management/getting_started
I have a website that uses the Twitter API (verrsion 1.1) with PHP and Zend framework 1 for validating the user name that is entered into a text input by a user of the application.
I created the app on Twitter and generated the Consumer Key (API Key), Consumer Secret (Secret API), Access Token and Access Token Secret.
General permissions: Read, write, and direct messages
Tokens permissions: Read and write
My PHP code for the authentication with Twitter is:
$config = array(
'version' => '1.1',
'signatureMethod' => 'HMAC-SHA1',
'callbackUrl' => 'http://example/main/twitter',
'siteUrl' => 'https://api.twitter.com/oauth',
'requestTokenUrl'=> 'https://api.twitter.com/oauth/request_token',
'accessTokenUrl' => 'https://api.twitter.com/oauth/access_token',
'authorizeUrl' => 'https://api.twitter.com/oauth/authorize',
'consumerKey' => self::$_consumeKey,
'consumerSecret' => self::$_consumeSecret
);
$session = new Zend_Session_Namespace('OAUTH_TWITTER');
$consumer = new Zend_Oauth_Consumer( $config );
$token = $consumer->getRequestToken();
$session->request_token = serialize($token);
$consumer->redirect();
When this code is executed, in the line:
$token = $consumer->getRequestToken();
returns the following error:
Could not retrieve a valid Token response from Token URL:
error code="215" Bad Authentication data.
I do not know what I did because previously was working perfectly. I researched for 2 weeks and still can not find the solution. I tried to create the application again, regenerate keys and tokens and change the time zone of my server to UTC but has not been solved.
If you need more information about me, please let me know.
I appreciate any information you can give me. Regards.
PD: sorry by my bad english
LinkedIn doesn't seem to like the idea of redirecting back to my test site.
This code directs me to the LinkedIn confirm page without any problems:
(This is pretty much a boilerplate example using Zend's OAuth)
$options = array(
'version' => '1.0',
'callbackUrl' => 'http://dev.local/',
'requestTokenUrl' => 'https://api.linkedin.com/uas/oauth/requestToken',
'userAuthorizationUrl' => 'https://api.linkedin.com/uas/oauth/authorize',
'accessTokenUrl' => 'https://api.linkedin.com/uas/oauth/accessToken',
'consumerKey' => [api],
'consumerSecret' => [secret]
);
$consumer = new Zend_Oauth_Consumer( $options );
// Start Requesting a LinkedIn Request Token
$token = $consumer->getRequestToken ();
// Store the LinkedIn Request Token
$_SESSION ['REQUEST_TOKEN'] = serialize ( $token );
// Redirect the Web User to LinkedIn Authentication Page
$consumer->redirect ();
However if my callback is http://dev.local/ it does not redirect, but if I specify a valid domain (like http://www.google.com) it redirects with no problem.
This behaviour happened recently (it was working fine until about a month ago). This is obviously a serious pain since I need to deploy code to be able to test anything.
Is this a problem people have experienced and has anyone found a way to get around?
it seems this is because LinkedIn changed their API, specifically how the api interacts with Oauth:
On the technical side, we've borrowed the OAuth 2.0 concept of the
"scope" parameter and incorporated it into our OAuth 1.0a and JS
Authentication flows.
Seems other apps, plugins and libraries are experiencing some difficulty with this as well.
I want my website to automatically post status updates to a particular twitter account using OAuth in PHP.
I test this using a URL
www.mysite.com/update_status
but it asks me for "user name" and "password", which is fine when I am testing it. But my website will not be able to insert this user name and password before posting the status update.
So the question is how can a website which is in the server, automatically post a status update to an account without user filling out the user name and password.
Is there any way to bypass this? I tried saving oAuth tokens, but it's not working.
Thank you for your answer in advance!
My recommendation:
1) Use a PHP library like http://github.com/abraham/twitteroauth.
2) Select your app on http://dev.twitter.com/apps and click on "My Access Token".
3) Us that access token as described on http://dev.twitter.com/pages/oauth_single_token.
Just tried this and it WORKS! And its SO SIMPLE to use!!
http://ditio.net/2010/06/07/twitter-php-oauth-update-status/
Got it working in under 5mins.
xAuth is able to do that, but Twitter only allows it for desktop and mobile apps.
In case you wanna try it, read this article and the API docs.
Try it with zend framework. As of version 1.10.8 minimal code required to post on Twitter is:
$token = new Zend_Oauth_Token_Access;
$token->setParams(array(
'oauth_token' => 'REPLACE_WITH_TOKEN',
'oauth_token_secret' => 'REPLACE_WITH_TOKEN_SECRET'
));
$twitter = new Zend_Service_Twitter(array(
'consumerSecret' => 'REPLACE_WITH_CONSUMER_SECRET',
'accessToken' => $token
));
$response = $twitter->status->update('REPLACE WITH MESSAGE');
All tokens and secrets can be accessed after registering your application on http://dev.twitter.com