I'm using php and downloaded the yahoo library to import yahoo user info.
I've already finished it and it has been working flawlessly, but now it has started to return:
Notice (8): Trying to get property of non-object
[APP/Vendor/Yahoo/Yahoo.inc, line 1036]
This notice appears after logging in through yahoo. When I debug $user->getProfile() it returns null.
I didn't change anything in my code that's why i don't have any idea what is causing it.
Please help!
This is the relevant part of my code:
App::import('Vendor', 'YahooInc', array('file' => 'Yahoo/Yahoo.inc'));
$session = YahooSession::requireSession($consumer_key,$consumer_secret,$app_id);
if (is_object($session)) {
$yahooUser = $session->getSessionedUser();
$yahooProfile = $yahooUser->getProfile();
}
You have to replace your current Yahoo Api library with the below github branch.
https://github.com/syamvilakudy/yos-social-php
Related
I am trying to set up Oauth with the YouTube Data API. I had a Laravel app which has Socialite set up. Out of the box YouTube isn't set up with this but I saw that there is a provider for YouTube here:
https://socialiteproviders.netlify.app/providers/you-tube.html
I have done all of the steps outlined on the page along with all routes that I need. I have also done the Oauth set up on Google Developer Console and got the client ID/secret key and set the callback.
When I use the login URL it works where I'm redirected for login with Google. The problem comes when the callback URL is reached. I get the error:
ErrorException
Undefined index: items
This occurs on the provider callback function which has the code:
$user = Socialite::driver('youtube')->user();
I have tried using stateless:
$user = Socialite::driver('youtube')->stateless()->user();
But get the same error. All caches have been cleared. I am pretty sure that the setup was done correctly as I'm also using the Twitch provider from https://socialiteproviders.netlify.app/providers/twitch.html which the setup was similar and it works correctly.
Please can anyone advise? Thanks.
Try selecting the fields you want to access first:
$user = Socialite::driver('youtube')->fields([
'items'
])->user();
I'm facing the same issue. Is it possible that the API has changed? If I take a look at the raw response there
I also stumbled onto this issue:
When I tested it, I did not got the error, but my colleague did so I figured it had something to do with the account that tried to connect.
I changed my approach from:
$user = Socialite::driver('youtube')->stateless()->user();
And just received tokens by doing this:
$socialite = Socialite::driver('youtube');
$code = $request->input('code');
$response = $socialite->getAccessTokenResponse($code);
$response will contain an array of tokens. I used these tokens to connect it to an existing user in my database.
I don't know if this is the solution for your workflow, but it is a way to get around the mysterious error.
The issue is due to YouTube no longer automatically creating a channel for your google/gmail account like it did in the past. This results in responses completely missing an items array.
if you dd($response->getBody()->getContents()) the response for an account that throws an error you'll see this.
I've made a pull request for this here. https://github.com/SocialiteProviders/YouTube/pull/8
I'm working on the development of a Twitter Oauth API. The project that is under development is available below.
I have encountered a problem and have trouble resolving it. The issue is; Twitter API functions such as status', friendship requests which I send out using the POST function do work.
Though, when int type data is Included, I get the following
error code: 32 message: "Could not authenticate you."
I get this when I include the statuses/update function with the in_reply_to_status_id function or with functions like favorites/create, favorites/destroy, statuses/retweet, statuses/unretweet which require int type data (ID).
Index.php Code: (My App Consumer Keys Placed)
<?php
session_start();
include("TwitterClass.php");
$twitter = new Twitter('srFixTitKV8f9WmJwF6VehhSF', 'GqSR29NQ0RoDBQ8gywQrsLV3vXowgFsSIMmueVQPm7E4ALAkNH');
$status = $twitter->post('statuses/update', ['status' => 'Test2!', 'in_reply_to_status_id' => '1057346977753636864'], true);
if ($status) {
echo 'Success!';
}
?>
The GitHub page for the project under development is available through the link below. Thank you for your help.
Project Github Page (TwitterClass.php source code)
Could be that you forgot to add is equal to true, like this: == true); instead of true);.
I am using the following link for using the Google Cloud Storage :
Google CLoud
I want to upload an object using insert function given in the above API.I am using PHP. The code i am using is as follows :
$StorageService = new Google_StorageService($client);
$objects = $StorageService->objects;
$gso = new Google_StorageObject();
$gso->setName('myobj');
$postbody = array(file_get_contents('buc.jpg'));
$resp = $objects->insert('mybucket', $gso, $postbody);
But i m getting Error as :
Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error calling POST https://www.googleapis.com/storage/v1beta1/b/mybucket/o: (400) Required' in /home/www/public_html/abc/google-api-php-client/src/io/Google_REST.php on line 66
What am i doing wrong please help me out..
There is some problem with the way i am sending the parameters. Please if anyone knows help me..
There is an example here :
Example
But that is in Java Please help me to do the same thing in PHP. Please help me out.
I figured out the answer. The code to be used is as follows :
$objects = $StorageService->objects;
$postbody = array('data' => file_get_contents('buc.jpg'));
$gso = new Google_StorageObject();
$gso->setName('mybuc');
$resp = $objects->insert('mybucket', $gso ,$postbody);
print_r($resp);
and then it works ..
I was not setting the parameter "data" in an array to be passed as a third parameter of the function. I Found out and it worked.
Buckets share a global namespace. You have to create your bucket before storing objects in it, and "mybucket" is not an available name.
If you go to the GCS browser at https://storage.cloud.google.com/, you can create your bucket there and then reference the existing bucket in your PHP code.
I had to add uploadType to get it to work as mentioned here: https://cloud.google.com/storage/docs/json_api/v1/objects/insert
$postbody = array('uploadType' => 'media', 'data' => file_get_contents('buc.jpg'));
Where is the data parameter documented?
I'm trying to create a web application that will allow a user to post a tweet from a form directly on the webpage, instead of using Twitter's own pre-built pop-up. The problem is, the snippet of code that I'm seeing around the web is not working:
$message = "Hello there! This is a tweet!";
$twitterObj->post('statuses/update', array('status' => "$message"));
And when I try to execute the code I get this error:
Warning: Invalid argument supplied for foreach() in /twitter/EpiOAuth.php on line 76
Warning: http_build_query() [function.http-build-query]: Parameter 1 expected to be Array or Object. Incorrect value given in /twitter/EpiOAuth.php on line 140
I'm building off the example and using the OAuth library found at this web address:
http://www.jaisenmathai.com/articles/twitter-php-sign-in.html
Does anyone have any tips?
EDIT
Problem solved! It turns out that this was the correct statement that I needed to use:
$twitterObj->post_statusesUpdate(array('status' => 'Message goes here.'));
This is what I use:
$message = "Hello there! This is a tweet!";
$twitterObj->OAuthRequest('https://twitter.com/statuses/update.xml', array('status' => $message), 'POST');
This is with the library found here: https://github.com/abraham/twitteroauth
I'm trying to get a user's credit balance with this code:
$obj = json_decode(
file_get_contents('https://api.facebook.com/method/users.getStandardinfo'.
'?uids='.$facebook_uid.'&fields=credit_balance&access_token='.
''.$access_token.'&format=json'));
I get error code 13 with this message:
The underlying FQL query made by this API call has encountered the following error: credit_balance is not a member of the user table.","request_args".
I've approved for credits in my game a lot of places and 95% sure on, that I've been accepted.
What to do?
Simon, if you have re-authenticated the user and retried then it is likely an issue on our end. Can you post your application ID and I will take a look.
I had the same problem. There are couple of things you need to do to get facebook credit balances in your app.
Get your App whitelisted by Facebook so you can call this API.
Use the code below to get the credit balances.
Facebook's own documentation didn't work either. (No surprise there) Instad I used the code below.
$accessTokenURL = 'https://graph.facebook.com/oauth/access_token&client_id=' .$app_id .'&client_secret=' .$secret .'&grant_type=client_credentials';
$accessToken = file_get_contents($accessTokenURL);
$creditsInfoURL = 'https://api.facebook.com/method/users.getStandardinfo?fields=credit_balance&format=json&uids=' .$query_uid.'&' .$accessToken;
$creditsInfo = file_get_contents($creditsInfoURL);
list($creditsArray) = json_decode($creditsInfo, true);
$fbcredbalance = 0;
if(isset($creditsArray['credit_balance'])) {
$fbcredbalance = $creditsArray['credit_balance'];
}