Posts tagged with spring-boot

I'm encountering an issue with the Google Ads API where I'm receiving the following error message:

Credentials failed to obtain metadata

This error occurs when making requests to the Google Ads API using the GoogleAdsService/Search method. Here's an example of the request and response details:

Request

MethodName: google.ads.googleads.v16.services.GoogleAdsService/Search Endpoint: googleads.googleapis.com:443 Headers: {developer-token=REDACTED, login-customer-id=9854212609, x-goog-api-client=gl-java/17.0.10__Oracle-Corporation gccl/31.0.0 gapic/31.0.0 gax/2.47.0 grpc/1.62.2} Body: customer_id: "9854212609" query: "SELECT campaign.id, campaign.name FROM campaign" 

Response

Headers: null Body: null Failure message: null Status: Status{code=UNAVAILABLE, description=Credentials failed to obtain metadata, cause=com.google.auth.oauth2.GoogleAuthException: com.google.api.client.http.HttpResponseException: 401 Unauthorized POST https://oauth2.googleapis.com/token 

...

Here are the details of my configuration:

  • I'm using Spring Boot for my application.
  • I have a google-ads.properties file where I've configured the necessary credentials such as clientId, clientSecret, refreshToken, developerToken, and loginCustomerId.
  • I've implemented the Google Ads client using the GoogleAdsClient class provided by the Google Ads Java library.
  • I've verified that the credentials are correct and have the necessary permissions to access the Google Ads API.

Despite these configurations, I'm still encountering the error mentioned above. I'm not sure what could be causing the issue. Any insights or suggestions on how to troubleshoot and resolve this would be greatly appreciated.

Thank you in advance for your help!

based on the provided error message and the details of the configuration, I expected the Google Ads API requests to authenticate successfully and return the requested data. However, the actual result was a failure with the message "Credentials failed to obtain metadata," indicating an authentication issue.

i have been trying to publish videos on a facebook page's story, but i havent been successful, i have tried using their apis and integrating with restfb as well, As for restfb, i was able to post on a facebook page's timeline, but not on their story, i have included the code showing my implementation using the facebook api and rest fb, thanks for checking out, i appreciate any assistance

public void postVideo(String contentUrl) throws MalformedURLException, FileNotFoundException, FacebookOAuthException {         Users loggedInUser = userService.getCurrentUser();         Socials social = socialsService.getSocialByPlatform(SocialPlatform.FACEBOOK);         UserSocials userSocial= userSocialsService.findUserSocial(loggedInUser, social).orElseThrow(()-> new UserException("User social not found"));         FacebookClient defaultFacebookClient = new DefaultFacebookClient(userSocial.getAccessToken(), Version.LATEST);         File videoFile = new File("uploads/" + contentUrl);         if (!videoFile.exists()) {             throw new FileNotFoundException("Video file not found at specified path.");         }         FileInputStream fileInputStream = new FileInputStream(videoFile); //       Implementation using facebook api //        MultiValueMap<String, Object> requestBody = new LinkedMultiValueMap<>(); //        requestBody.add("file", new FileSystemResource("uploads/" + contentUrl)); //        HttpHeaders headers = new HttpHeaders(); //        headers.setContentType(MediaType.MULTIPART_FORM_DATA); //        FBVideoStoryStartResponse fbVideoStoryStartResponse = webClient.post() //                .uri("https://graph.facebook.com/v18.0/"+userSocial.getSocialUserId()+"/video_stories", uriBuilder -> uriBuilder //                        .queryParam("upload_phase", "start") //                        .build()) //                .retrieve() //                .bodyToMono(FBVideoStoryStartResponse.class) //                .block(); //        System.out.println(fbVideoStoryStartResponse); //        if(fbVideoStoryStartResponse != null){ //            FBVideoStoryUploadStatus fbVideoStoryUploadStatus = webClient.post() //                    .uri("https://rupload.facebook.com/video-upload/v18.0/" + fbVideoStoryStartResponse.getVideoId()) //                    .headers(httpHeaders -> httpHeaders.addAll(headers)) // Add the headers to the request //                    .bodyValue(requestBody) //                    .retrieve() //                    .bodyToMono(FBVideoStoryUploadStatus.class) //                    .block(); //            System.out.println(fbVideoStoryUploadStatus); //            assert fbVideoStoryUploadStatus != null; //            if(fbVideoStoryUploadStatus.isSuccess()){ //                FBVideoStoryFinishResponse fbVideoStoryFinishResponse = webClient.post() //                        .uri("https://graph.facebook.com/v18.0/"+userSocial.getSocialUserId()+"/video_stories", uriBuilder -> uriBuilder //                                .queryParam("video_id", fbVideoStoryStartResponse.getVideoId()) //                                .queryParam("upload_phase", "finish") //                                .build()) //                        .retrieve() //                        .bodyToMono(FBVideoStoryFinishResponse.class) //                        .block(); //                System.out.println(fbVideoStoryFinishResponse); //            } //        } //      Implementation using restfb         FBVideoStoryStartResponse fbVideoStoryStartResponse1 = defaultFacebookClient.publish(userSocial.getSocialUserId() + "/video_stories", FBVideoStoryStartResponse.class,                 Parameter.with("upload_phase", "start"));         String videoUploadID = fbVideoStoryStartResponse1.getVideoId();         System.out.println(videoUploadID);         GraphResponse graphResponse = defaultFacebookClient.publish(videoUploadID, GraphResponse.class, BinaryAttachment.with(videoFile.getName(), fileInputStream));         GraphResponse graphResponse1 = defaultFacebookClient.publish(userSocial.getSocialUserId() + "/video_stories", GraphResponse.class,                 Parameter.with("video_id", videoUploadID),                  Parameter.with("upload_phase", "finish"),                  Parameter.with("video_state", "PUBLISHED"),                 Parameter.with("description", "A short description text"));             try {                 fileInputStream.close();             } catch (IOException e) {                 throw new RuntimeException(e);             } } 

So using restfb, i get the error "There is a problem uploading your video, Please try again with another file" and i have tried with multiple files below a minute but still the same result.

How can I integrate my WhatsApp for business (not using any 3rd party tools like Pabbly, WANotifier, etc.) to send a pdf document (Purchase Order details) to the customers without having to send a welcome text message and the customer not having to reply back with anything to receive the pdf document (Purchase Order details)?.

Note: if this is not possible then how does MakeMyTrip and book my show works where in which when we book tickets or shows we receive a pdf file (booking details) without we in person initiating the conversation of asking the booking details.

Went through the official MetaforDevelopers document https://developers.facebook.com/docs/whatsapp/cloud-api but couldn't find any solutions.

If somebody finds something out of the document link attached above related to my requirement, please let me know! Thanks in advance!

i am using java library client for web application authentication, i produce authorization url using client secret and client id,also i provided a redirect url within google api console,but i don't know if it is necessary for me to create this server to receive refresh token? i mean in production i should provide a separate server to receive the refresh token?(redirect url comes to this server) the main problem is user should paste the produced url on browser by himself but i want to open browser authmaticly , the second one is about reciving the refresh token i am not sure about creating another server to recieve refreshcode and i can't use service accounts i am going with web flow authentication.

 UserAuthorizer userAuthorizer =                 UserAuthorizer.newBuilder()                         .setClientId(ClientId.of(clientId, clientSecret))                         .setScopes(SCOPES)                         .setCallbackUri(URI.create(OAUTH2_CALLBACK_URL_CONFIGURED_AT_GOOGLE_CONSOLE))                         .build();         baseUri = URI.create("http://localhost:" + simpleCallbackServer.getLocalPort());         System.out.printf(                 "Paste this url in your browser:%n%s%n",                 userAuthorizer.getAuthorizationUrl(loginEmailAddressHint, state, baseUri)); 

and this is local server to receive refresh token:

private static class SimpleCallbackServer extends ServerSocket {         private AuthorizationResponse authorizationResponse;         SimpleCallbackServer() throws IOException {             // Passes a port # of zero so that a port will be automatically allocated.             super(0);         }         /**          * Blocks until a connection is made to this server. After this method completes, the          * authorizationResponse of this server will be set, provided the request line is in the          * expected format.          */         @Override         public Socket accept() throws IOException {             Socket socket = super.accept();         } }