How to post image on facebook timeline using graph api 4.0? - laravel

I am creating an API to post on my Facebook timeline using graph API 4.0. For this, i am first creating an album and then post image in that album.
here is the code
$facebook = new Facebook(array(
'appId' => 'APP_ID',
'secret' => 'APP_SECRET',
'cookie' => true,
));
$user = $facebook->getUser();
if ($user) {
//Create an album
$album_details = array(
'message'=> 'Album desc',
'name'=> 'Album name'
);
$create_album = $facebook->apiRequest('/me/albums/{user-access-token}', 'post', $album_details);
dd($create_album);
}
which returns an error
Raw Provider API response: {\"error\":{\"message\":\" This object does not exist or does not support this action\"
But when i gave page token instead of a user access token , it works fine. I am new to this. So, i have no idea how to solve this.

The Facebook API no longer permits publishing to personal profile feeds.
https://developers.facebook.com/docs/graph-api/reference/v4.0/user/feed#publish
As of April 24,2018, the publish_actions permission has been removed. Please see the Breaking Changes Changelog for more details. To provide a way for your app users to share content to Facebook, we encourage you to use our Sharing products instead.

Related

Google calendar api not showing the organizer name and sending notification emails - laravel

I'm using a laravel package for the google calendar API integration. In that, I am able to create events with just attendees only. I've tried creating organizer but it's not coming up. The following is the code I've used. The organizer name here defaults to the email from which the API credentials are created also the email notifications are not coming.
The package I'm using is spatie/laravel-google-calendar
Can anyone tell me what I'm doing wrong here?
Event::create([
'name' => 'Latest Event dsfdsfsdfsdf',
'location' => '800 Howard St., San Francisco, CA 94103',
'description' => 'A chance to hear more about Google\'s developer products.',
'startDateTime' => Carbon\Carbon::now(),
'endDateTime' => Carbon\Carbon::now()->addHour(),
'sendNotifications' => true,
'sendUpdates' => 'all',
'organizer' => array('email' => 'test#gmail.com','displayName' => 'Darshan')
'attendees' => array(
array('email' => 'test#gmail.com','displayName' => 'Darshan', 'organizer' => true),
array('email' => 'darshan#test.com','displayName' => 'Ryan')
)
]);
The package doesn't support adding an organizer yet. You could either add the functionality to the package or you could use the Google ApiClient directly. The Google Sdk does have a setOrganizer method which should work similar to the setAttendees method that is called in the Event class.
Apparently the word "organizer" is bit of a misnomer and it actually refers to the calendar that the event is created on. Have a look at this question and it's comments.

list blogs list of blogger in Google PHP SDK

I am using Google API SDK in CakePHP application.
I have to list the blogs owned by the user after authenticating the application.
The user will select from the list of blogs and I will record the blog ID to make further requests.
According to the documentation, we need to make GET request to
GET https://www.googleapis.com/blogger/v3/users/self/blogs?key=YOUR-API-KEY
But I have my API Key and user's access token.
How can I list the blogs using the access token?
I tried using the SDK Services
$client = new \Google_Client();
$client->setApplicationName(GOOGLE_APP_NAME);
$client->setClientId(GOOGLE_CLIENT_ID);
$client->setClientSecret(GOOGLE_CLIENT_SECRET);
$client->setAccessToken($access_token);
$client->setAccessType("offline"); // offline access
$client->setIncludeGrantedScopes(true); // incremental auth
$client->addScope('https://www.googleapis.com/auth/userinfo.email');
$client->addScope('https://www.googleapis.com/auth/blogger');
$callback_url = Router::url(['prefix' => 'dashboard', 'controller' => 'SharingLogin', 'action' => 'bloggerCallback'], true);
$client->setRedirectUri($callback_url);
$service = new \Google_Service_Blogger($client);
$listblog = $service->blogs;
debug($listblog);
But this lists nothing and empty array object.

Magento Rest API Issue When Using PayPal Payment Advanced

I'm using Magento's Rest API to sell item from my Wordpress based site. I am having an issue when I try to use PayPal Payment Advanced to complete the transaction. Here is the code below:
$paymentArray = array(
"method" => "payflow_advanced",
'cc_cid' => $_POST['cccvv'],
'cc_owner' => $_POST['firstName'] . " ". $_POST['lastName'],
'cc_number' => $_POST['ccnumber'],
//'cc_type' => "MC",
'cc_exp_year' => $_POST['ccmonth'],
'cc_exp_month' => $_POST['ccyear'],
);
$resultPaymentMethod = $client->call($session, 'cart_payment.method', array($shoppingCartIncrementId, $paymentArray));
When I run the code, it comes back as "true" but the api never hits PayPal and authorizes the transaction.
Once you var_dump($resultPaymentMethod) and see what's it displaying the output..

Facebook losing logged in user with ajax

I am writing a Facebook app and have used the Facebook php SDK so it can be authorized server side. I can see this is working because after authorization when Facebook redirects back to my app, I have the following code in my index.php...
require_once 'facebook.php';
$facebook = new Facebook(array(
'appId' => '111111111111111',
'secret' => '11111111111111111111111111111111',
'cookie' => true
));
// Get User ID
$user = $facebook->getUser();
...and $user returns not null. So far, so good!
I have a link on my app that loads content via ajax when clicked. Here's the JS:
$.post('my_content.php', {
action: 'render'
}, function(res){
if (res.html.length) {
$('.content').html(res.html);
}
},'json');
The problem is, the my_content.php script seems to be losing the fact the user has logged in and authorized the app.
The code I run in the my_content.php script to check whether the user is logged in is the same as in index.php
require_once 'facebook.php';
$facebook = new Facebook(array(
'appId' => '111111111111111',
'secret' => '11111111111111111111111111111111',
'cookie' => true
));
// Get User ID
$user = $facebook->getUser();
This time though $user = $facebook->getUser() returns null.
Is there a way to check if the user is logged in and authorized when running a PHP script with an AJAX call?
Should I store something in a session variable in my index.php script?
EDIT
After even more reading, I'm wondering if I need to retrieve the access token using the JavaScript SDK and pass it to my_content.php. Does anyone know if that's the correct way to do it?
EDIT 2
Turns out the line giving me the problem isn't $user = $facebook->getUser():
It is this one
$user_profile = $facebook->api('/me');
This line fails with the error 'OAuthException: An active access token must be used to query information about the current user.'
Strangely though, if I do this
$access_token = $facebook->getAccessToken();
$user = $facebook->getUser();
echo $access_token;
echo $user;
I do indeed have an access token and a user ID, so it looks like it may well be the bug reported by CBroe - check comments below.

Magento - Customer Not Logged in After Redirect From External Page

I'm having a lot of trouble getting a customer to stay logged in after I have created a new account. I'm creating them an account and adding products to a cart from an external site, and then sending them to Magento store. What I want to have happen is:
A customer goes to a signup page and enters relevant information.
They go to a new page where they can choose to add free samples to their cart.
After picking samples. their account is created and they are redirected to the Magento store with the samples in their cart.
The problem I'm having is between steps 2 and 3. I create an account using the Magento's SOAP API with the following:
$customerInfo = array('firstname' => $custFirstname, 'lastname' => $custLastname, 'email' => $email, 'password_hash' => md5( $new_password ), 'store_id' => 34, 'website_id' => 25,'group_id' => 9);
// Call API method customer.create
$newCustomerId = $client->call( $session, 'customer.create', array( $customerInfo ) );
I then return their customer ID, which I pass to another function which actually logs them in and adds products to their cart:
public static function _addSamplesToCart($customer_id, $sample_one, $sample_two, $sample_three){
Mage::getSingleton("core/session", array("name" => "frontend"));
$customerSession = Mage::getSingleton('customer/session', array("name" => "frontend"));
$customerSession->init("customer_bn_us");
$customerSession->loginById($customer_id);
$cart = Mage::getSingleton('checkout/cart');
$cart->addProductsByIds($idArray);
$cart->save();
$cart->getCheckoutSession()->setCartWasUpdated(true);
}
These functions are actually called from AJAX post requests, so when I get a successful return value from _addSamplesToCart, I do a simple javascript redirect (window.location ="http://www.myhostname.net/welcome") and it correctly takes me there, but I'm not logged in.
I've been looking around all afternoon and trying a few different things and nothing has worked. I've also tried doing a hidden form submit to /customer/account/loginPost and it still doesn't work. I have verified that it's correctly creating an account in Magento. My only hunch is that I'm doing this with a mix of AJAX and PHP so somehow the cookies or sessions are getting mixed up?
If you are trying to login from an hostname different from the one used by the Magento store, it cannot work. You can verify this by checking if a frontend cookie is created after the AJAX call.
I suggest you to create a new controller in Magento that receives the id of the customer just created and executes the code you wrote in your function:
www.myhostname.net/autologin/myaction/13 (where 13 is the id of the customer just created).
Obviously you should add something else to avoid security issues.

Resources