I used weibo oauth api in magento for connect user with weibo.
But now weibo is broken and it completely get token but display error
when we retrieve user data using authentication token.error is as follows..
i am using this code the use can successfully login but after that there is an error like this
[error_code] => 401
[error] => 40109:consumer_key_refused!
my code is here for after login\
$c = new WeiboClient( WB_AKEY , WB_SKEY , $_SESSION['last_key']['oauth_token'] , $_SESSION['last_key']['oauth_token_secret'] );
$ms = $c->home_timeline();
$me = $c->verify_credentials();
$ms = $c->show_user($userid);
I found weibo new oauth2.0 authentication api that solve my problem.Use this if any one have problem in weibo user authentication..
Weibo-Oauth2 and follow Application scenarios step.
For get access token,you need to use form POST method instead of GET.so you use this code.
$opts = array('http' =>
array(
'method' => 'POST',
'header' => "Content-Type: text/xml\r\n"
)
);
$context = stream_context_create($opts);
$uri= 'https://api.weibo.com/oauth2/access_token?client_id='.WB_AKEY.'&client_secret='.WB_SKEY.'&grant_type=authorization_code&redirect_uri='.YOUR_REGISTERED_REDIRECT_URI.'&code='your authorization code;
$authkey1 = file_get_contents($uri,false,$context);
$decoded_auth1 = json_decode($authkey1,true);
And use this url to get authenticate user data..
$userinfo = file_get_contents("https://api.weibo.com/2/users/show.json?access_token=".$access_token."&uid=".$userid);
$decoded_userinfo = json_decode($userinfo, true);
Hope this help to anyone..
Use weibo_2 with oauth2. please.
Related
In a Joomla application I am getting a user info as follows and then I need to save the user info as a contact in a Dynamics 365 database through their REST API.
$user = JFactory::getUser();
$username = $user->username;
$name = $user->name;
I have looked up Dynamics documents around Web API and REST API like this and this, but none of them provide useful info how I can call the API to add a new contact. Currently, I am connecting to Dynamics 365 web application via this url: http://example.com:8088/mysite/api/data/v8.2. The linked post also talks about REST API, but only querying. I'm looking for a way to post data to Dynamics CRM using REST API.
The payload to create Contact using crm webapi will look like this: Read more
POST [Organization URI]/api/data/v8.2/contacts HTTP/1.1
Content-Type: application/json; charset=utf-8
OData-MaxVersion: 4.0
OData-Version: 4.0
Accept: application/json
{
"firstname": "Arun",
"lastname": "Vinoth"
}
Sorry am not from PHP background, but this link may help you.
Update:
I browsed little bit. Found the below code sample from SO answer. Update the [Organization URI] with CRM URL, for ex. https://testorg.crm.dynamics.com
$url = '[Organization URI]/api/data/v8.2/contacts';
$data = array('firstname' => 'Arun', 'lastname' => 'Vinoth');
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dump($result);
struggling to understand the oauth2 token and refresh token processes
ive got this code
$url = 'https://www.googleapis.com/oauth2/v3/token';
$data = array('client_id' => 'clientid', 'client_secret' => 'secret','refresh_token' => 'token','grant_type' => 'refresh_token');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded",
'method' => 'POST',
'approval_prompt'=>'force',
'access_type'=>'offline',
'content' => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
that code above gives me an access token , and i followed this link suggested by one fellow stackoverflower, pinoyyid, BUT , im confunsed on how to correctly use the resulting access token to access drive and copy a file...
all the process ive seen usually involves $client = new Google_Client() and im not sure on how to use the whole POST http://..... thing, so basically i need to figure out if i use the access token i got with the code above in a new instance of google client, or i simply do a post to a url with necesary info ( which im not clear on also ) any help/clarification is appreciated guys really
EDIT #1
what i want to achieve is to allow the end user to access my drive via my webpage, to let them copy a spreadsheet in my drive , and access it via my website, to store data on the spreadsheet,the spreadsheet will always be on my drive, never on the end user
EDIT #2
code as per your posts is as follows, using the service account,,,,the files are inside that gmail account which i created on the api console a service account
<?php
require 'Google/autoload.php';
$client = new Google_Client();
// Replace this with your application name.
$client->setApplicationName("TEST");
// Replace this with the service you are using.
$service = new Google_Service_Drive($client);
// This file location should point to the private key file.
$key = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/number-privatekey.p12');
$user_to_impersonate = 'admin#testpr.com';
$cred = new Google_Auth_AssertionCredentials(
'number#developer.gserviceaccount.com',
array('https://www.googleapis.com/auth/drive'), ****//this here has to be drive not drive.file
$key,
'notasecret',
'http://oauth.net/grant_type/jwt/1.0/bearer',
$user_to_impersonate
);
$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion();
}
$originFileId = "longnumber";
$copyTitle = 'copied';
$newfile = copyFile($service, $originFileId, $copyTitle);
print_r($newfile);
function copyFile($service, $originFileId, $copyTitle)
{
$copiedFile = new Google_Service_Drive_DriveFile();
$copiedFile->setTitle($copyTitle);
try {
return $service->files->copy($originFileId, $copiedFile);
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
}
return NULL;
}
?>
so got it working just now, ty all for your time guys really and edited my post to reflect the dang thing
If you want to give the end user access to your drive, you have to give your application authority to make API calls on behalf of a user (in this case you) in your domain. For this you have to set up a service account and generate a p12 key in the Google Developers Console. You have to enter the https://www.googleapis.com/auth/drive API scope in your Admin Console as well.
Full explanation and examples can be found here: https://developers.google.com/api-client-library/php/auth/service-accounts.
To achieve this you also need the Google API's client library: https://github.com/google/google-api-php-client (also mentioned in the Google manual).
Code example to let users make API calls on behalf of one of your accounts: https://developers.google.com/api-client-library/php/guide/aaa_oauth2_service
I want to integrate xero api for public application in php.
I am stuck with oauth application authorization
I have download code from github https://github.com/XeroAPI/XeroOAuth-PHP (find on xero api code sample for public application)
I am using following code:
require('/../lib/XeroOAuth.php');
require('/../_config.php');
$useragent = "Xero-OAuth-PHP Public";
$signatures = array (
'consumer_key' => 'app_consumre_key',
'shared_secret' => 'app_secret_key',
'core_version' => '2.0'
);
$XeroOAuth = new XeroOAuth ( array_merge ( array (
'application_type' => XRO_APP_TYPE,
'oauth_callback' => OAUTH_CALLBACK,
'user_agent' => $useragent
), $signatures ) );
include 'tests.php';
I am passing following xml data:
$xml = "<Invoices>
<Invoice>
<Type>ACCREC</Type>
<Contact>
<Name>Martin Hudson</Name>
</Contact>
<Date>2013-05-13T00:00:00</Date>
<DueDate>2013-05-20T00:00:00</DueDate>
<LineAmountTypes>Exclusive</LineAmountTypes>
<LineItems>
<LineItem>
<Description>Monthly rental for property at 56a Wilkins Avenue</Description>
<Quantity>4.3400</Quantity>
<UnitAmount>395.00</UnitAmount>
<AccountCode>200</AccountCode>
</LineItem>
</LineItems>
</Invoice>
</Invoices>";
$params = array (
'oauth_callback' => OAUTH_CALLBACK
);
$response1 = $XeroOAuth->request ( 'GET', $XeroOAuth->url ( 'RequestToken', '' ), $params );
if ($XeroOAuth->response ['code'] == 200)
{
$outhtoken = $XeroOAuth->response ['response'];
$oauth_exp = explode('&',$outhtoken);
$oauth_exp_token = explode('=',$oauth_exp[1]);
$oauth_token = $oauth_exp_token[1];
}
First I am oauth token, and passing into oauth invoice url
$response = $XeroOAuth->request('POST', $XeroOAuth->url('Invoices', 'core'), array('oauth_token'=>$oauth_token), $xml);
Now I am getting 401 error in response, oauth token mismatch
What mistake I am doing?
If you are getting OAuth errors with Xero, their OAuth Issues article is helpful to provide a possible solution. That said, "token mismatch" isn't mentioned - nor could I find reference to the error in the Xero community.
Based on what you've posted, the first question is if you've completed the OAuth process? There are three main steps (get a request token, user authorisation, get an access token) and your example above only shows the first step. The public.php file you've referenced contains all the steps.
If you do have the OAuth process running smoothly, then make sure the OAuth access token and secret are being passed with your request (only the token is shown in your sample request). You can set these in the XeroOAuth object, so the final request could look like
$XeroOAuth->config ['access_token'] = $oauth_token;
$XeroOAuth->config ['access_token_secret'] = $oauth_token_secret;
$XeroOAuth->request('POST', $XeroOAuth->url('Invoices', 'core'), array(), $xml);
I've made a gist with the complete process based off the XeroOauth-PHP public.php that demonstrates both OAuth and creating an invoice.
Xero is no longer supporting oAuth 1.0
and you must have to use latest Git hub Repo with Xero OAuth 2.0
https://github.com/XeroAPI/xero-php-oauth2
I am using artdarek-oauth-4-laravel for the Login to my website via Facebook, twitter and google.
Login part is working fine. But I want to get some more data from these api, like if user is registering through the google then I am looking for their general info as well as google contact list, or if the user is registering from Facebook then I am trying to get the /me and /friend-list etc.
Here, I am just taking the case of google.
I have set the config like this
'Google' => array(
'client_id' => '***********************************',
'client_secret' => '***********************************',
'scope' => array('userinfo_email', 'userinfo_profile', 'https://www.google.com/m8/feeds/'),
),
My Controller Function is this:-
public function loginWithGoogle()
{
$code = Input::get( 'code' );
$googleService = OAuth::consumer( 'Google' );
if ( !empty( $code ) )
{
$token = $googleService->requestAccessToken( $code );
// $result = json_decode( $googleService->request( 'https://www.googleapis.com/oauth2/v1/userinfo' ), true );
$result = json_decode( $googleService->request( 'https://www.google.com/m8/feeds/contacts/default/full' ), true );
echo json_encode($result);
}
else {
// get googleService authorization
$url = $googleService->getAuthorizationUri();
// return to google login url
return Redirect::to( (string)$url );
}
}
This code leads me to the google api and asks for all the permission that I have set in the scope of the service. Here once I got the access token after exchanging the code parameter with the api, I am calling the url to return me the contact list but it fails. And I am getting this message from the laravel :-Failed to request resource.
If I call the commented $result request, it returns me the result.
So, I wanted to know how can we use this library for the data other than login and register. In case of retrieving facebook friendlist the same thing happens but the login works. (My Facebook App has the permission to get friendlist).
Any help is appreciated.
Check this response, https://stackoverflow.com/a/26488136/434790.
It worked for me. The culprit: alt=json to be added to https://www.google.com/m8/feeds/contacts/default/full
I want to implement a Twitter login in my project. My project is coded in CodeIgniter.
Can somebody give me a step by step process to implement this?
just refer the following links- integrating-twitter-api-with-codeigniter and
Auth---3rd-Party-Authentication
//use Codeigniter-TwitterOAuth
//https://github.com/MunGell/Codeigniter-TwitterOAuth
//download url: https://github.com/MunGell/Codeigniter-TwitterOAuth/archive/master.zip
//Usage
// There are two ways to load library to Codeigniter. Automatically within ./config/autoload.php or directly in your controller by adding this line:
$this->load->library('twitteroauth');
//Create an instance:
$connection = $this->twitteroauth->create($consumer, $consumer_secret, $access_token, $access_token_secret);
//Verify your authentication details:
$content = $connection->get('account/verify_credentials');
//Send a message:
$data = array(
'status' => $message,
'in_reply_to_status_id' => $in_reply_to
);
$result = $connection->post('statuses/update', $data);
hi try this oauth library by philsturgeon oauth